-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnondecreasingArray.py
More file actions
31 lines (31 loc) · 1001 Bytes
/
nondecreasingArray.py
File metadata and controls
31 lines (31 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution:
def checkPossibility(self, nums: List[int]) -> bool:
flag=1
c=0
if len(nums)==1 :
return True
for i in range(1,len(nums)) :
if nums[i]<nums[i-1] :
t=nums[i]
nums[i]=nums[i-1]
for j in range(1,len(nums)) :
if nums[j]<nums[j-1] :
flag=0
break
if flag==0:
nums[i]=t
if i!=len(nums) :
if i!=1 :
nums[i-1]=nums[i-2]
else :
nums[i-1]=-100000
for j in range(1,len(nums)) :
if nums[j]<nums[j-1] :
flag=-2
break
break
#print(nums)
if flag==-2 :
return False
else :
return True