Skip to content

Commit 22c47cf

Browse files
authoredOct 30, 2023
Create 1299-replace-elements-with-greatest-element-on-right-side.rb
1 parent ad0f0a4 commit 22c47cf

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def replace_elements(arr)
2+
right_max = -1
3+
(arr.length - 1).downto(0) do |i|
4+
cur_max = [right_max, arr[i]].max
5+
arr[i] = right_max
6+
right_max = cur_max
7+
end
8+
arr
9+
end

0 commit comments

Comments
 (0)
Please sign in to comment.