File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ 풀이
3
+ - 정렬 후 각 interval을 비교하여 풀 수 있습니다
4
+ Big O
5
+ - N: intervals의 길이
6
+ - Time complexity: O(NlogN)
7
+ - sort.Slice -> average O(NlogN)
8
+ - 두 번째 for -> O(N)
9
+ - Space complexity: O(logN)
10
+ - golang의 sort package는 pdqsort를 사용합니다 -> O(logN)
11
+ 퀵소트의 재귀 호출 스택 깊이를 고려하여야 합니다
12
+ */
13
+
14
+ import "sort"
15
+
16
+ func canAttendMeetings (intervals [][]int ) bool {
17
+ if len (intervals ) <= 1 {
18
+ return true
19
+ }
20
+
21
+ sort .Slice (intervals , func (i , j int ) bool {
22
+ if intervals [i ][0 ] == intervals [j ][0 ] {
23
+ return intervals [i ][1 ] < intervals [j ][1 ]
24
+ }
25
+ return intervals [i ][0 ] < intervals [j ][0 ]
26
+ })
27
+ for i := 0 ; i < len (intervals )- 1 ; i ++ {
28
+ if intervals [i ][1 ] > intervals [i + 1 ][0 ] {
29
+ return false
30
+ }
31
+ }
32
+ return true
33
+ }
You can’t perform that action at this time.
0 commit comments