/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { private int res=0; private int count=0; public int kthSmallest(TreeNode root, int k) { inorder(root,k); return res; } public void inorder(TreeNode root, int k){ if(root==null)return; inorder(root.left,k); count++; if(count==k){ res=root.val; return; } inorder(root.right,k); }}