Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1ab40ed

Browse files
Replace Elements with Greatest Element on Right Side
1 parent 2d68726 commit 1ab40ed

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
""" https://leetcode.com/problems/replace-elements-with-greatest-element-on-right-side/ """
2+
3+
# Time Limit Exceeded
4+
# 42 / 90 testcases passed
5+
6+
class Solution:
7+
def replaceElements(self, arr):
8+
newArr = []
9+
10+
for i in range(len(arr) - 1):
11+
max = arr[i + 1]
12+
13+
for j in range(i + 1, len(arr) - 1):
14+
if (arr[j + 1] > max):
15+
max = arr[j + 1]
16+
17+
newArr.append(max)
18+
19+
newArr.append(-1)
20+
return newArr
21+
22+
print(Solution().replaceElements([17,18,5,4,6,1]))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /