注意判断[3,4,2,3]这种改不了的情况.
class Solution: def checkPossibility(self, nums: List[int]) -> bool: use=False for i in range(len(nums)-1): if nums[i]>nums[i+1]: if not use: use=True a=nums.copy() a[i]=a[i+1] b=nums.copy() b[i+1]=b[i] if (sorted(a)!=a) and (sorted(b)!=b): return False else: return False return True