(lintcode)第632题二叉树的最大节点
2017-08-23 14:43
232 查看
要求:在二叉树中寻找值最大的节点并返回。
样例
给出如下一棵二叉树:
返回值为
代码如下:
public class Solution {
/**
* @param root the root of binary tree
* @return the max ndoe
*/
public TreeNode treenode=new TreeNode(-1000000000);
public TreeNode maxNode(TreeNode root) {
// Write your code here
if(root==null)
return null;
else{
if(root.val>treenode.val)
treenode=root;
maxNode(root.left);
maxNode(root.right);
}
return treenode;
}
}
样例
给出如下一棵二叉树:
1 / \ -5 2 / \ / \ 0 3 -4 -5
返回值为
3的节点,返回值是节点,不是数值。
代码如下:
public class Solution {
/**
* @param root the root of binary tree
* @return the max ndoe
*/
public TreeNode treenode=new TreeNode(-1000000000);
public TreeNode maxNode(TreeNode root) {
// Write your code here
if(root==null)
return null;
else{
if(root.val>treenode.val)
treenode=root;
maxNode(root.left);
maxNode(root.right);
}
return treenode;
}
}
相关文章推荐
- lintcode 632. 二叉树的最大节点
- LintCode 第632题 二叉树的最大节点
- 一、lintcode刷题记录--矩阵面积、二叉树的最大节点、整数排序、删除链表中的元素
- [Lintcode]二叉树的最大节点
- 【LintCode 入门】632. 二叉树的最大节点
- LintCode-二叉树的最大节点
- 二叉树最大节点-lintCode
- 【LintCode-632】二叉树的最大节点(Java实现)
- 二叉树的最大节点-LintCode
- LintCode 二叉树的最大节点
- LintCode 二叉树的最大节点
- 二叉树的最大节点-LintCode
- LintCode入门练习——632. 二叉树的最大节点
- 【入门】lintcode 632: 二叉树的最大节点
- LintCode入门练习——632. 二叉树的最大节点
- LintCode 二叉树的最大节点
- LintCode-(632)二叉树的最大节点
- Lintcode 入门-632. 二叉树的最大节点
- 利用栈结构实现二叉树的非递归遍历,求二叉树深度、叶子节点数、两个结点的最近公共祖先及二叉树结点的最大距离
- 利用栈结构实现二叉树的非递归遍历,求二叉树深度、叶子节点数、两个结点的最近公共祖先及二叉树结点的最大距离