/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
if(!root)
return 0;
int left = maxDepth(root->left);
int right = maxDepth(root->right);
int maxDepth = left > right ? left : right;
return maxDepth+1;
}
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int getNode(struct TreeNode* root){
if(!root)
return 0;
int left = getNode(root->left);
int right = getNode(root->right);
int result = left + right + 1;
return result;
}
int countNodes(struct TreeNode* root) {
return getNode(root);
}
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int countNodes(struct TreeNode* root) {
struct TreeNode** stack = (struct TreeNode**)malloc(sizeof(struct TreeNode*) * 100);
int totalNum = 0;
int stackTop = 0;
if(root)
stack[stackTop++] = root;
while(stackTop)
{
struct TreeNode* cur = stack[--stackTop];
totalNum++;
if(cur->left)
stack[stackTop++] = cur->left;
if(cur->right)
stack[stackTop++] = cur->right;
}
return totalNum;
}