一、题目
二、代码
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution
{
//中序遍历 取第k-1下标位置的即可
List<Integer> re = new LinkedList<>();
public int kthSmallest(TreeNode root, int k)
{
mid(root);
return re.get(k-1);
}
public void mid(TreeNode cur)
{
if(cur.left != null) mid(cur.left);
re.add(cur.val);
if(cur.right != null) mid(cur.right);
}
}