URL:http://www.lintcode.com/en/problem/binary-tree-maximum-node/
Find the maximum node in a binary tree, return the node.
Example
Given a binary tree:
1
/ \
-5 2
/ \ / \
0 3 -4 -5
public class Solution {
/* class TreeNode {
TreeNode l, r;
int val;
}*/
TreeNode maxNode(TreeNode root) {
if (root == null) return root;
TreeNode l = maxNode(root.left);
TreeNode r = maxNode(root.right);
return max(root, max(l, r));
}
TreeNode max(TreeNode l, TreeNode r) {
if (l == null) return r;
if (r == null) return l;
return l.val > r.val ? l : r;
}
/* public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num = in.nextInt();
}*/
}