```
class Solution(object):
def kthSmallest(self, root, k):
n = [0]
def dfs(root):
if root.left and dfs(root.left) == k:
return root.left.val
if root.right and dfs(root.right) == k:
return root.right.val
n[0] += 1
return n[0]
return dfs(root)
```