题目
思路
代码
python
class Solution:
def checkPossibility(self, nums: List[int]) -> bool:
n =len(nums)
flag=0
for index,element in enumerate(nums):
if index<=n-2:
if flag==1:
if element>nums[index+1]:
return False
elif element>nums[index+1]:
flag=1
if index!=0:
if nums[index-1]<=nums[index+1]:
nums[index]=nums[index-1]
else:
nums[index+1]=element
return True