题解 | #通用解法 dps 完全二叉树结点数#
完全二叉树结点数
http://www.nowcoder.com/practice/512688d2ecf54414826f52df4e4b5693
/**
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
*/
class Solution {
public:
int dpsserch(TreeNode* root){
if(root == nullptr){
return 0;
}else{
int ans = 0;
ans = dpsserch(root->left)+dpsserch(root->right)+1;
return ans;
}
}
int nodeNum(struct TreeNode* head) {
return dpsserch(head);
}
};