/**
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
*/
class Solution {
public:
int getDepth(TreeNode* head) {
if (!head) {
return 0;
}
return max(getDepth(head->left), getDepth(head->right)) + 1;
}
int nodeNum(struct TreeNode* head) {
if(!head) {
return 0;
}
int leftDepth = getDepth(head->left);
int rightDepth = getDepth(head->right);
if (leftDepth == rightDepth) {
return pow(2, leftDepth) + nodeNum(head->right);
} else {
return pow(2, rightDepth) + nodeNum(head->left);
}
}
};