```
public class Solution {
int num;
public int kthSmallest(TreeNode root, int k) {
this.num = k;
return preFind(root);
}
public Integer preFind(TreeNode curr) {
if (curr != null) {
Integer temp = preFind(curr.left);
if (temp != null) {
return temp;
}
if (this.num > 1) {
this.num--;
} else {
return curr.val;
}
temp = preFind(curr.right);
if (temp != null) {
return temp;
}
}
return null;
}
}
```