三种情况:
1、nums=[4,2,5],nums[i]<nums[i-1],此时只需要改变nums[i-1],[1,2,5]
2、nums=[1,4,2,5],i>.1,nums[i]<nums[i-1],此时调整nums[i-1],满足nums[i-2]<=nums[i-1]<=nums[i],[1,2,2,5]
3、nums=[3,4,2,5],i>.1,nums[i-2]>nums[i],此时调整nums[i-1]不行,只能让nums[i]=nums[i-1],[3,4,4,5]
1 def checkPossibility(nums): 2 N = len(nums) 3 count = 0 4 for i in range(1, N): 5 if nums[i] < nums[i - 1]: 6 count += 1 7 if i == 1 or nums[i] >= nums[i - 2]: 8 nums[i - 1] = nums[i] 9 else: 10 nums[i] = nums[i - 1] 11 print(nums) 12 return count <= 1
标签:count,12,数列,nums,665,递减 From: https://www.cnblogs.com/wanxueyu/p/16768815.html