LintCode 二叉树的最大节点
2017-04-08 21:20
218 查看
题目描述:
在二叉树中寻找值最大的节点并返回。
样例
给出如下一棵二叉树:
1
/ \
-5 2
/ \ / \
0 3 -4 -5
返回值为 3 的节点。
思路分析:
遍历一遍记录最大值。
ac代码:
在二叉树中寻找值最大的节点并返回。
样例
给出如下一棵二叉树:
1
/ \
-5 2
/ \ / \
0 3 -4 -5
返回值为 3 的节点。
思路分析:
遍历一遍记录最大值。
ac代码:
class Solution { public: /** * @param root the root of binary tree * @return the max node */ int maxx=-99999; TreeNode *nmax; void max(TreeNode *root) { if(root==NULL) return ; if(root->val>maxx) { maxx=root->val; nmax=root; } max(root->left); max(root->right); } TreeNode* maxNode(TreeNode* root) { // Write your code here if(root==NULL) return NULL; max(root); return nmax; } };
相关文章推荐
- 二叉树最大节点-lintCode
- LintCode-二叉树的最大节点
- (lintcode)第632题二叉树的最大节点
- 【LintCode-632】二叉树的最大节点(Java实现)
- LintCode 二叉树的最大节点
- 二叉树的最大节点-LintCode
- 二叉树的最大节点-LintCode
- LintCode-(632)二叉树的最大节点
- LintCode入门练习——632. 二叉树的最大节点
- LintCode 二叉树的最大节点
- 【入门】lintcode 632: 二叉树的最大节点
- LintCode入门练习——632. 二叉树的最大节点
- Lintcode 入门-632. 二叉树的最大节点
- [Lintcode]二叉树的最大节点
- LintCode 第632题 二叉树的最大节点
- 一、lintcode刷题记录--矩阵面积、二叉树的最大节点、整数排序、删除链表中的元素
- lintcode 632. 二叉树的最大节点
- 【LintCode 入门】632. 二叉树的最大节点
- 编程之美--求二叉树中节点的最大距离
- [面试备忘]求二叉树中节点最大距离 & 分层遍历二叉树