#include<vector>
#include<algorithm>
struct Tree {
int val;
struct Tree *left;
struct Tree *right;
Tree(int x) :
val(x), left(NULL), right(NULL) {
}
};
/**
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
*/
class Solution {
public:
/*int nodeNum(struct TreeNode* head) {
if(head==nullptr) return 0;
return 1+nodeNum(head->left)+nodeNum(head->right);
}*/
//方法二
int nodeNum(TreeNode* head){
int left=0;
int right=0;
TreeNode* ldeep;
TreeNode* rdeep;
for(ldeep=head;ldeep!=nullptr;ldeep=ldeep->left) left++;
for(rdeep=head;rdeep!=nullptr;rdeep=rdeep->right) right++;
if(right==left){
return pow(2,right)-1;
}
return 1+nodeNum(head->left)+nodeNum(head->right);
}
};