File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution :
2+ def merge (self , intervals : List [List [int ]]) -> List [List [int ]]:
3+ """
4+ Intuition:
5+ ์ ๋ ฌ๋ intervals์ ์ํํ๋ฉด์ ์ด์ ์ ์ธํฐ๋ฒ๊ณผ ํ์ฌ ์ธํฐ๋ฒ์ด
6+ ๊ฒน์น๋ค๋ฉด, ์ด๋ฅผ ๊ฐฑ์ ํด์ค๋ค.
7+ ๊ฒน์น์ง ์๋๋ค๋ฉด, ์๋ก์ด ์ธํฐ๋ฒ์ ์ถ๊ฐํ๋ค.
8+
9+ Time Complexity:
10+ O(N log N):
11+ ์ต์ด์ ์ ๋ ฌ์ ํ๋ฏ๋ก, O(N log N)์ด๋ค.
12+ ์ดํ ํ๋ฒ ์ค์บ์ ํ๋ฏ๋ก O(N)์ด๋ค.
13+ ๋ฐ๋ผ์ ์๊ฐ ๋ณต์ก๋๋ O(N log N)์ด๋ค.
14+
15+ Space Complexity:
16+ O(N):
17+ answer์ N๊ฐ์ ๊ฐ์ ์ ์ฅํ๋ฏ๋ก O(N)์ด๋ค.
18+ """
19+ sorted_intervals = sorted (intervals )
20+
21+ answer = [sorted_intervals [0 ]]
22+ for start , end in sorted_intervals [1 :]:
23+ prev_start , prev_end = answer [- 1 ]
24+ if prev_end >= start :
25+ answer [- 1 ][1 ] = max (prev_end , end )
26+ else :
27+ answer .append ([start , end ])
28+ return answer
You canโt perform that action at this time.
0 commit comments