原题题目
代码实现(首刷自解)
/*** Definition for a binary tree node.* struct TreeNode {* int val;* struct TreeNode *left;* struct TreeNode *right;* };*/int count;void visit(struct TreeNode* root,int tempmax)
{
if(root){
if(root->val > tempmax){
tempmax = root->val;count++;}else if(root->val == tempmax) count++;visit(root->left,tempmax);visit(root->right,tempmax); }
}int goodNodes(struct TreeNode* root){
count = 0;visit(root,root->val);return count;
}