MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / merge

Function merge

tasks/56.go:7–35  ·  view source on GitHub ↗
(intervals [][]int)

Source from the content-addressed store, hash-verified

5}
6
7func merge(intervals [][]int) [][]int {
8 mpStart := make(map[int]int)
9 mpEnd := make(map[int]int)
10 max := 0
11 for _, interval := range intervals {
12 mpStart[interval[0]]++
13 mpEnd[interval[1]]++
14 max = maxInt(max, interval[1])
15 }
16 var ret [][]int
17 for i := 0; i <= max; i++ {
18 if mpStart[i] > 0 {
19 sum := 0
20 el := make([]int, 2)
21 el[0] = i
22 for {
23 sum += mpStart[i]
24 sum -= mpEnd[i]
25 if sum == 0 {
26 break
27 }
28 i++
29 }
30 el[1] = i
31 ret = append(ret, el)
32 }
33 }
34 return ret
35}
36
37func maxInt(a, b int) int {
38 if a > b {

Callers

nothing calls this directly

Calls 1

maxIntFunction · 0.70

Tested by

no test coverage detected