二叉树最大节点
Java版:
public class Solution {
/**
* @param root the root of binary tree
* @return the max ndoe
*/
public TreeNode maxNode(TreeNode root) {
// Write your code here
if (root == null)
return root;
TreeNode left = maxNode(root.left);
TreeNode right = maxNode(root.right);
return max(root, max(left, right));
}
TreeNode max(TreeNode a, TreeNode b) {
if (a == null)
return b;
if (b == null)
return a;
if (a.val > b.val) {
return a;
}
return b;
}
}