Skip to content

Commit 557a0f9

Browse files
committed
feat: meeting-rooms
1 parent 5d244b9 commit 557a0f9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

meeting-rooms/invidam.go.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Intuition
2+
It is a simple `greedy` problem.
3+
간단한 그리디 분류의 문제다.
4+
# Approach
5+
1. To find earliest interval, sort intervals by start time in ascending order.
6+
2. After sorting, while iterating through the array, check for conflict: the current interval's start time shoud be smaller than the next interval's end time.
7+
# Complexity
8+
- Time complexity: $$O(nlog(n))$$
9+
- Space complexity: $$O(n)$$
10+
11+
(n is length of `intervals`)
12+
# Code
13+
```go
14+
func CanAttendMeetings(intervals []*Interval) bool {
15+
sort.Slice(intervals, func(i, j int) bool {
16+
return intervals[i].Start < intervals[j].Start
17+
})
18+
19+
curr := &Interval{-1, -1}
20+
for _, next := range intervals {
21+
if curr.End > next.Start {
22+
return false
23+
}
24+
curr = next
25+
}
26+
27+
return true
28+
}
29+
```

0 commit comments

Comments
 (0)