-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution1854.go
More file actions
43 lines (36 loc) · 894 Bytes
/
Copy pathsolution1854.go
File metadata and controls
43 lines (36 loc) · 894 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
36
37
38
39
40
41
42
43
package solution1854
// ============================================================================
// 1854. Maximum Population Year
// URL: https://leetcode.com/problems/maximum-population-year/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/1854
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_maximumPopulation
Benchmark_maximumPopulation-24 17257236 68.27 ns/op 0 B/op 0 allocs/op
PASS
*/
func maximumPopulations(logs [][]int) int {
const (
loRange = 1950
hiRange = 2050
)
population := make([]int, 100)
for _, log := range logs {
for i := log[0]; i < log[1]; i++ {
year := i - loRange
population[year]++
}
}
var pop int
var year int
for y, n := range population {
if n > pop {
pop = n
year = y
}
}
return year + loRange
}