1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 public int kthSmallest(TreeNode root, int k) {
List<Integer> nums = new ArrayList<>();

find_num(root, nums, k);

return nums.get(k-1);
}
public void find_num(TreeNode root, List<Integer> nums, int k){
if(root != null){
find_num(root.left, nums, k);
nums.add(root.val);
if(nums.size() == k){
System.out.print(root.val + "here \n");
return;
}
find_num(root.right, nums, k);
}
}