Skip to content

Commit b8c42a3

Browse files
Create 1299_replace_elements_with_greatest_element_on_right_side.java
1 parent 71d4c5c commit b8c42a3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int[] replaceElements(int[] arr) {
3+
int rightMax = -1;
4+
for (int i = arr.length - 1; i >= 0; i--) {
5+
int newMax = Math.max(rightMax, arr[i]);
6+
arr[i] = rightMax;
7+
rightMax = newMax;
8+
}
9+
return arr;
10+
}
11+
}

0 commit comments

Comments
 (0)