Skip to content

Commit 3bd69e7

Browse files
authored
Merge pull request neetcode-gh#1447 from daredev127/104-Maximum-Depth-of-Binary-Tree
Created 1299-Replace-Elements-With-Greatest-Element-On-Right-Side.cs
2 parents ebcd7a4 + 79805fd commit 3bd69e7

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+
public class Solution {
2+
public int[] ReplaceElements(int[] arr) {
3+
int max = -1;
4+
for(int i = arr.Length-1; i >= 0; i--) {
5+
int newMax = Math.Max(arr[i], max);
6+
arr[i] = max;
7+
max = newMax;
8+
}
9+
return arr;
10+
}
11+
}

0 commit comments

Comments
 (0)