[LintCode]Binary Tree Maximum Node(C++)

xiaoxiao2021-02-28  113

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; } };
转载请注明原文地址: https://www.6miu.com/read-24345.html

最新回复(0)