LCP 61. 气温变化趋势

气温变化趋势

解法一: 循环

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
func temperatureTrend(temperatureA []int, temperatureB []int) int {
ans := 0
cur := 0
n := len(temperatureA)
for i := 1; i < n; i++ {
if compare(temperatureA[i], temperatureA[i-1]) == compare(temperatureB[i], temperatureB[i-1]) {
cur++
ans = max(ans, cur)
} else {
cur = 0
}
}
return ans
}

func compare(num1, num2 int) int {
if num1 == num2 {
return 0
} else if num1 > num2 {
return 1
}
return -1
}
作者

wuhunyu

发布于

2024-06-17

更新于

2025-01-15

许可协议