O(n).
public class Solution {
public int kthSmallest(TreeNode root, int k) {
// save the inorder of the tree
// from left to right, return kth element in the list
List<Integer> ret = new ArrayList<>();
inorder(root, ret);
return ret.get(k-1);
}
public static void inorder(TreeNode root, List<Integer> ret) {
if (root == null) return;
inorder(root.left, ret);
ret.add(root.val);
inorder(root.right, ret);
}
}