class Solution {
List<Integer> list = new ArrayList<>();
public void dfs(TreeNode root){
if(root == null) return;
dfs(root.left);
list.add(root.val);
dfs(root.right);
}
public int kthSmallest(TreeNode root, int k){
list = new ArrayList<>();
dfs(root);
for(int i = 0; i < list.size(); i++){
if(i == k - 1)
return list.get(i);
}
return -1;
}
}