-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path775.py
20 lines (20 loc) · 846 Bytes
/
775.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
__________________________________________________________________________________________________
sample 368 ms submission
class Solution:
def isIdealPermutation(self, A: List[int]) -> bool:
for i, n in enumerate(A):
if abs(i-n) > 1: return False
return True
__________________________________________________________________________________________________
sample 13408 kb submission
class Solution:
def isIdealPermutation(self, A: List[int]) -> bool:
min_expected = -1
for i in range(len(A)):
if i + 2 >= len(A):
break
min_expected = max(min_expected, A[i])
if A[i+2] < min_expected:
return False
return True
__________________________________________________________________________________________________