Example: 4 / \ 2 8 / \ 5 10 Output ==> 10
1. If the root
node is null, return null
.
2. If the right node of root
is null
, return root
.
3. Else recurse through right nodes. i.e. return findMax(root.right)
public TreeNode findMax(TreeNode root) { }
C
Java
Python