Skip to content

Commit 4372832

Browse files
committed
add sol
1 parent 1cd5bb4 commit 4372832

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

leetcode/daily/3105/sol.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func longestMonotonicSubarray(nums []int) int {
6+
res := 1
7+
tmp := 1
8+
9+
for i, v := range nums[1:] {
10+
if nums[i] < v {
11+
tmp++
12+
res = max(res, tmp)
13+
} else {
14+
tmp = 1
15+
}
16+
}
17+
18+
tmp = 1
19+
for i, v := range nums[1:] {
20+
if nums[i] > v {
21+
tmp++
22+
res = max(res, tmp)
23+
} else {
24+
tmp = 1
25+
}
26+
}
27+
28+
return res
29+
}
30+
31+
func main() {
32+
nums := []int{1,4,3,3,2}
33+
34+
fmt.Println(longestMonotonicSubarray(nums))
35+
}

0 commit comments

Comments
 (0)