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

Commit4acd838

Browse files
authored
Create 0189-rotate-array.kt
1 parent8ae983c commit4acd838

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

‎kotlin/0189-rotate-array.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
classSolution {
2+
funrotate(nums:IntArray,k:Int):Unit {
3+
4+
funreverse(from:Int,to:Int) {
5+
var f= from
6+
var t= to
7+
while (f< t) {
8+
nums[f]= nums[t].also { nums[t--]= nums[f++] }
9+
}
10+
}
11+
12+
val modK= (k% nums.size)
13+
reverse(0, nums.lastIndex)
14+
reverse(0, modK-1)
15+
reverse(modK, nums.lastIndex)
16+
}
17+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp