Skip to content

Commit 001c24a

Browse files
author
chen-shiwei
committed
feat: [贪心] 376
1 parent 25c13e7 commit 001c24a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package _376_摆动序列
2+
3+
func wiggleMaxLength(nums []int) int {
4+
var (
5+
cur int
6+
pre int
7+
result = 1
8+
)
9+
10+
if len(nums) <= 1 {
11+
return len(nums)
12+
}
13+
14+
for i := 1; i < len(nums); i++ {
15+
cur = nums[i] - nums[i-1]
16+
if (cur > 0 && pre <= 0) || (cur < 0 && pre >= 0) {
17+
result++
18+
pre = cur
19+
}
20+
}
21+
22+
return result
23+
}

0 commit comments

Comments
 (0)