The number of nodes (**n**) in the tree is irrelevant to the complexity. My code inorder traverse the tree and it stops when it finds the Kth node. The time complexity for this code is O(k).

=======Update============

The number of nodes in the tree does change the time complexity. The program actually goes to the left bottom node first and start from there to search for the Kth smallest. Thus the time complexity should be O(log(n) + K). What do you think ?

```
public class Solution {
public int kthSmallest(TreeNode root, int k) {
ArrayList<Integer> buffer = new ArrayList<Integer>();
inorderSearch(root, buffer, k);
return buffer.get(k-1);
}
public void inorderSearch(TreeNode node, ArrayList<Integer> buffer, int k){
if(buffer.size() >= k)
return;
if(node.left != null){
inorderSearch(node.left, buffer, k);
}
buffer.add(node.val);
if(node.right != null){
inorderSearch(node.right, buffer, k);
}
}
```

}