-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path1299.py
32 lines (29 loc) · 1023 Bytes
/
1299.py
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
32
__________________________________________________________________________________________________
sample 60 ms submission
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
maximum = -1
res = [arr[-1]]
i = len(arr)-1
while i>0:
if arr[i] > maximum:
maximum = arr[i]
res.append(maximum)
i-=1
res.reverse()
res[-1] = -1
return res
__________________________________________________________________________________________________
sample 64 ms submission
class Solution:
def replaceElements(self, arr: List[int]) -> List[int]:
if len(arr)==1:
return [-1]
mx=-1
for i in range(len(arr)-1,-1,-1):
if mx<arr[i]:
mx , arr[i] = arr[i] , mx
else:
arr[i]=mx
return arr
__________________________________________________________________________________________________