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 #53 on September 15, 2026 11:03.
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.
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/binary-search-tree-iterator/
Problem Summary
BST에서 크기 순으로 동작하는 이터레이터를 만드는 문제. 메소드는 next(), hasNext() 두개를 구현하면 된다.
Solution
초기화 때 inorder으로 전부 돌아서 배열에 넣은 다음 하나씩 출력하는 방법이 간단하지만 메모리는 O(n)이긴 하다.
스택을 쓰면 O(h)로 메모리를 줄일 수 있다.
하지만 결과에서의 실행 시간은 배열에 전부 집어넣은 방식이 더 빠르고 메모리도 적게 사용한다... 오차가 있을 수 있겠지만 단순 2번씩 제출 결과는 그렇다.
Source Code
Inorder Array
Inorder Stack
All reactions