注意判断[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

 

相关文章:

  • 2022-01-29
  • 2021-11-10
  • 2021-09-10
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-07-07
  • 2022-02-24
猜你喜欢
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案