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 #132 on September 15, 2026 11:11.
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/regions-cut-by-slashes/
Problem Summary
슬래시로 나뉜 영역의 개수를 세는 문제.
Solution
원본 그리드에서 개수를 세는건 꽤 복잡하다. 그래서 크기를 키운 3x3 그리드에서 영역의 개수를 셀 수 있다.
출처: 에디토리얼
시간복잡도는 O(n^2)
2x2 그리드로 풀기
나는 처음에 4x4로 풀었는데 잘 생각해보니 2x2로도 될 것 같다.
원본 그리드를 참고해서 / 이면 대각선으로 1,3분면을 이동 가능하게 하고 \이면 2,4분면을 이동 가능하게 만들면 2x2 그리드로도 풀 수 있다.
예시로
위 입력을 2x2 그리드로 확장하면
이 되는데, (0,2)에서는 원본 그리드에서 / 이므로 (1,1)로 대각선 이동이 가능하다고 볼 수 있다.
Source Code
All reactions