真·过山车解法
忘记了竟然有极大值这个东西了,就事论事,我竟然真的用过山车的思路AC了,就是解得有点慢!!最后仔细想想,也算半个动态规划吧。😀
class Solution: def getMaxLength(self , n , num ): begin,end =0,1 tre = [] maxn = 0 nums = -1 for i in range(n-1): tre.append(num[i+1]-num[i]) print(tre) for x in tre: if x == 0: maxn = max(maxn,nums) begin,end = 0,1 elif x > 0: begin = 1 if end == 1: maxn = max(maxn,nums+1) nums = 0 end = 0 nums += 1 else: end = 1 if begin == 1: nums += 1 if end == 1: maxn = max(maxn,nums+1) return maxn