forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1094.go
More file actions
35 lines (30 loc) · 684 Bytes
/
1094.go
File metadata and controls
35 lines (30 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
type interval [][]int
func (s interval) Len() int {
return len(s)
}
func (s interval) Less(i, j int) bool {
if s[i][0] == s[j][0] {
return s[i][1] < s[j][1]
}
return s[i][0] < s[j][0]
}
func (s interval) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func carPooling(trips [][]int, capacity int) bool {
tmp := make([][]int, 0)
for _, v := range trips {
tmp = append(tmp, []int{v[1], v[0]})
tmp = append(tmp, []int{v[2], -v[0]})
}
sort.Sort(interval(tmp))
n := 0
for _, v := range tmp {
n += v[1]
fmt.Println(n)
if n > capacity {
return false
}
}
return true
}