[LeetCode] 230. Kth Smallest Element in a BST
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the…
[LeetCode] 230. Kth Smallest Element in a BST
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.
Example 1:

Input: root = [3,1,4,null,2], k = 1
Output: 1
Example 2:

Input: root = [5,3,6,2,4,null,null,1], k = 3
Output: 3
Constraints:
- The number of nodes in the tree is n.
- 1 <= k <= n <= 104
- 0 <= Node.val <= 104
Ans
[embed]
Solution
看到 BST 就知道老東西了
實際上這題就是考 Binary Tree Traversal 的方法概念
(Inorder, Preorder, Postorder)
因為是老東西了 我就不介紹了
如果有刷 LeetCode Easy 題目就知道
메타데이터
- post_id
- 1094be4fc17e
- slug
- leetcode-230-kth-smallest-element-in-a-bst-1094be4fc17e
- url
- https://medium.com/@kosjason/leetcode-230-kth-smallest-element-in-a-bst-1094be4fc17e
- canonical_url
- https://medium.com/@kosjason/leetcode-230-kth-smallest-element-in-a-bst-1094be4fc17e
- author_url
- https://medium.com/@kosjason
- status
- ok
- fetched_at
- 2026-07-27 06:20:56