Created
December 30, 2019 01:44
-
-
Save luoheng23/ad339274c98739cbe5c49433c93f9f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func max(x, y int) int { | |
if x > y { | |
return x | |
} | |
return y | |
} | |
func replaceElements(arr []int) []int { | |
res := make([]int, len(arr)) | |
res[len(res)-1] = -1 | |
if len(res) >= 2 { | |
res[len(res)-2] = arr[len(arr)-1] | |
} | |
for i := len(res) - 3; i >= 0; i-- { | |
res[i] = max(arr[i+1], res[i+1]) | |
} | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment