Skip to content

Commit 924fc25

Browse files
authored
Create replace-elements-with-greatest-element-on-right-side.py
1 parent 81316b2 commit 924fc25

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def replaceElements(self, arr):
6+
"""
7+
:type arr: List[int]
8+
:rtype: List[int]
9+
"""
10+
curr_max = -1
11+
for i in reversed(xrange(len(arr))):
12+
arr[i], curr_max = curr_max, max(curr_max, arr[i])
13+
return arr

0 commit comments

Comments
 (0)