Easy Java O(n) code


#1

public class Solution {
private ArrayList list;
public int kthsmallest(TreeNode A, int B) {
list=new ArrayList<>();
inorder(A);
return list.get(B-1);
}

public void inorder(TreeNode A) {
    if(A!=null) {
        inorder(A.left);
        list.add(A.val);
        inorder(A.right);
    }
    else return ;
}

}