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 #42 on September 15, 2026 11:01.
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/remove-invalid-parentheses/
Problem Summary
괄호가 맞도록 최소한의 문자를 제거해서 올바른 괄호 문자열을 출력하는 문제.
Solution
처음엔 간단한 완전탐색 dfs를 했는데 시간이 너무 오래 걸림. (심지어 초반 코드는 시간 초과라 최적화를 조금 했지만 9s 넘게 걸렸다)
=> 최소한의 문자를 제거하는 것이므로 BFS 방식으로 변경
현재 상태를 level이란 set으로 두자. level에서 가능한 문자열이 있으면 리턴하고 아니라면 그 level의 문자열 중에서 모든 문자를 하나씩 제거해서 다음 level에 집어넣는 방식으로 작성하였다. (discuss 참고함)
Source Code
DFS (9405 ms)
BFS (192 ms)
All reactions