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

Commit6f8f113

Browse files
authored
Create 0061-rotate-list.kt
1 parent371d59f commit6f8f113

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎kotlin/0061-rotate-list.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
classSolution {
2+
funrotateRight(head:ListNode?,_k:Int):ListNode? {
3+
head?:returnnull
4+
5+
var length=1
6+
var tail= head
7+
while (tail?.next!=null) {
8+
tail= tail?.next
9+
length++
10+
}
11+
12+
val k=_k% length
13+
if (k==0)return head
14+
15+
var cur= head
16+
for (iin0 until (length- k-1))
17+
cur= cur?.next
18+
19+
val newHead= cur?.next
20+
cur?.next=null
21+
tail?.next= head
22+
23+
return newHead
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp