@angelvivienne As always, answers with 0 explanation. How did you arrive at the k-1-count if k > count + 1? Whats the reasoning? How did you arrive at that?

@ManuelP Thank you for your complaint. first, I want to clarify that I don't have other goals to post my solution.
I will modify my solutions and join the discussion topic. And I am happy that you find problems in my codes and hope I can learn something from you. Best wishes! : )

I'm not sure whether I under stand James comment, I think he's talking about after you setting the result value, you can directly return from there without go on recurse on right branch.

@mahk The worst case time complexity is definitely O(n). Suppose the k-th smallest element is actually the last node, you will have to count the whole tree.
Besides, even the first step of counting the totally number of left branch is O(n/2). n/2 is greater than log(n) already.

your code is different from almost all of others‘ which are recursive.
I just think that so much people copy the code from others.
so I voted you an up!

@sophie2509 In this, size of sub-trees are computed repeatedly which is slow. Rather, go inorder(bottom-up for left sub tree and top-down for right sub tree) and whenever size equals k, return the node.