1299. Replace Elements with Greatest Element on Right Side
🟩 Easy
Solution
My Solution
func replaceElements(arr []int) []int {
num := -1
for i:=len(arr)-1; i>=0; i-- {
if arr[i] > num {
num, arr[i] = arr[i], num
} else {
arr[i] = num
}
}
return arr
}

Leetcode: link
Previous1295. Find Numbers with Even Number of DigitsNext1342. Number of Steps to Reduce a Number to Zero
Last updated
Was this helpful?