4
/ \
2 8
/ \
5 10
K = 2, Output = 8
size + 1
is equal to k
, return that node
.
null
then, return null
.not null
then find the the size of the right subtree of this node.size + 1
is equal to k then return
this node.k
is less than right size then recurse with root.right i.e. return findKthLargest(root.right, k)
return findKthLargest(root.left,
k-rightSize-1);
public TreeNode findKthLargest(TreeNode root, int k) { }
C
Java
Python