Skip to content

Commit 3df93ab

Browse files
authored
Merge pull request #2127 from Zhaoshan-Duan/1299
Create: 1299 Replace-Elements-with-Greatest-Element-on-Right-Side.kt
2 parents d7539fb + 652a4a4 commit 3df93ab

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
fun replaceElements(arr: IntArray): IntArray {
3+
val res = IntArray(arr.size)
4+
var max = -1
5+
6+
arr.reversed().forEachIndexed { i, value ->
7+
res[i] = max
8+
max = maxOf(max, value)
9+
}
10+
return res.reversed().toIntArray()
11+
}
12+
}

0 commit comments

Comments
 (0)