解题思路
中序遍历 递归
利用二叉查找树中序遍历有序的特点。
class Solution {private int cnt = 0;private int res = 0;public int kthSmallest(TreeNode root, int k) {inOrder(root,k);return res;}private void inOrder(TreeNode root, int k){if(root==null||cnt>k)return;inOrder(root.left, k);cnt++;if(cnt==k)res=root.val;inOrder(root.right, k);}}
