uncommited problems

This commit is contained in:
2022-07-06 00:33:16 +01:00
parent e061a8602f
commit 0c78e204ef
10 changed files with 194 additions and 2 deletions

17
wiggle-subsequence/sol.go Normal file
View File

@@ -0,0 +1,17 @@
package main
func wiggleMaxLength(nums []int) int {
// Current's value only matters in terms of negative / 0 / positive.
// The numerical value doesn't get used and therefore can be messed with.
current, count := 0, len(nums)
for i := 0; i < len(nums)-1; i++ {
new := nums[i+1] - nums[i]
if (current > 0 && new > 0) || (current < 0 && new < 0) || new == 0 {
count--
}
if new != 0 {
current = new
}
}
return count
}