# leecode 230. Kth Smallest Element in a BST

public int kthSmallest(TreeNode root, int k) {
if (root == null)
return 0;
List<Integer> list = new ArrayList<Integer>();
getList(root, list);
//排序
Collections.sort(list);
//取结果，题意是结果一定会存在，所以直接取就行了
return list.get(k - 1);
}
//遍历二叉树，将数据存放到集合中
public void getList(TreeNode root, List<Integer> list) {
if (root == null)
return;
getList(root.left, list);
getList(root.right, list);
}

• 本文已收录于以下专栏：

## 【LEETCODE】230-Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. No...

## Leetcode 230. Kth Smallest Element in a BST (Medium) (cpp)

Leetcode 230. Kth Smallest Element in a BST (Medium) (cpp)

## LeetCode 230. Kth Smallest Element in a BST 解题报告

LeetCode 230. Kth Smallest Element in a BST 解题报告

## 230. Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. ...

## leetcode-230-Kth Smallest Element in a BST

Kth Smallest Element in a BST   Given a binary search tree, write a function kthSmallest to ...

## <LeetCode OJ> 230. Kth Smallest Element in a BST

230. Kth Smallest Element in a BST My Submissions Question Total Accepted: 32753 Total Submissio...

## leetcode -- 230. Kth Smallest Element in a BST 【遍历 + 计数】

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)