use global variable java solution

  • 0

    public int globalcount = 0;
    public int result = 0;
    public int kthSmallest(TreeNode root, int k) {
    if(root == null) return 0;
    kthSmallest(root.left, k);
    if(globalcount == k) result = root.val;
    kthSmallest(root.right, k);
    return result;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.