You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #52 on September 15, 2026 11:02.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/kth-smallest-element-in-a-bst/
Problem Summary
BST가 주어질 때 K번째 작은 원소를 구하는 문제
Solution
BST를 탐색하면서 K번째 작은 원소가 나오면 리턴하면 된다.
BST 탐색 방법 중 inorder 탐색을 하면(왼쪽 서브트리, 자신, 오른쪽 서브트리) 크기 순으로 탐색할 수 있고 이를 배열에 넣은 다음에 배열에서 k-1 인덱스의 원소를 뽑아내면 된다.
중간에 k번 탐색을 했다면 바로 리턴하는 식으로 가지치기는 할 수 있으나 어차피 O(n) 이므로 큰 의미는 없다.
Source Code
All reactions