Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9999adc

Browse files
authored
Merge pull requestneetcode-gh#1256 from tharunkanna14/patch-5
Create 1299_replace_elements_with_greatest_element_on_right_side.go
2 parentsf072120 +3b4c7e4 commit9999adc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
funcfindMaxElement(rightMaxint,lastElementint)int {
2+
iflastElement>rightMax {
3+
rightMax=lastElement
4+
}
5+
returnrightMax
6+
}
7+
8+
funcreplaceElements(arr []int) []int {
9+
varrightMaxint=-1
10+
fori:=len(arr)-1;i>=0;i-- {
11+
varnewMaxint=findMaxElement(rightMax,arr[i])
12+
arr[i]=rightMax
13+
rightMax=newMax
14+
}
15+
returnarr
16+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp