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 #74 on September 15, 2026 11:05.
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/find-the-shortest-superstring/
Problem Summary
모든 단어를 substring으로 갖는 가장 짧은 문자열을 구하는 문제.
Solution
처음에는 어려운데 비트마스크 DP를 쓰면 된다.
단어들을 뒤로 이어붙인다고 생각하고, 붙인 단어는 visited 처리를 비트마스크로 할 수 있다.
이러면 꽤 풀만한 문제가 된다.
suffix 함수는 단어를 뒤로 붙일 때 앞 단어의 중복되는 부분을 제거한 suffix 만 추출하는 함수이다.
마지막 words에 빈 문자열을 더하는건 코드를 간결하게 하기 위함이다.
전체 흐름은 디스커션 참고함. (https://leetcode.com/problems/find-the-shortest-superstring/discuss/1225543/Python-dp-on-subsets-solution-3-solutions-%2B-oneliner-explained)
Source Code
All reactions