class Solution {
public:
/**
* @param root the root of binary tree
* @return the max node
*/
TreeNode* max = new TreeNode(INT_MIN);
TreeNode* maxNode(TreeNode* root) {
// Write your code here
if (root == NULL) return NULL;
if (root->val > max->val) max = root;
maxNode(root->left);
maxNode(root->right);
return max;
}
};
[LintCode]Binary Tree Maximum Node(C++)
最新推荐文章于 2024-06-07 15:46:49 发布