1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| func wiggleMaxLength(nums []int) int { var count, preDiff, curDiff int count = 1 if len(nums) < 2 { return count } for i := 0; i < len(nums)-1; i++ { curDiff = nums[i+1] - nums[i]
if (curDiff > 0 && preDiff <= 0) || (preDiff >= 0 && curDiff < 0) { preDiff = curDiff count++ } } return count }
|