本质:局部最优推导整体最优
摆动序列
class Solution:def wiggleMaxLength(self, nums: List[int]) -> int:res = []if len(nums) == 1 or (len(nums) == 2 and nums[0] == nums[1]):return 1res.append(nums[1] - nums[0])r = 2i = 2while r < len(nums):multi = nums[r] - nums[i-1]if res[-1]* multi < 0:res.append(multi)r += 1i = relse:r += 1return len(res) + 1
我这个写法只要遇到条件合适的就输出了,没有等到条件最好的