@redace85 great answer! but why my code running wrong,here is my answer below,if you know ,please tell me~

#define max(a,b) ((a)>(b)?(a):(b))

static int len = 1;
int count(struct TreeNode *left, struct TreeNode *right){
if (left == NULL&&right == NULL) return len;
else if (left == NULL&&right != NULL) {
len++;
return count(right->left, right->right);
}
else if (left != NULL&&right == NULL){
len++;
return count(left->left, left->right);
}
else {
len++;
return max(count(left->left, left->right), count(right->left, right->right));
}
}
int maxDepth(struct TreeNode* root) {
if (root == NULL) return 0;
return count(root->left, root->right);
}