java solution with inorder and recursion


  • 0
    F

    '''
    public class Solution {
    public int num=0;
    public int val=0;
    public int kthSmallest(TreeNode root, int k) {
    inorder(root, k);
    return val;
    }
    public void inorder(TreeNode root, int k){
    if(root!=null){
    inorder(root.left, k);
    num++;
    if(num==k){
    val=root.val;
    return;
    }
    inorder(root.right, k);
    }
    return;
    }
    }
    '''


Log in to reply
 

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