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

Commit9acaf25

Browse files
authored
Create 0147-insertion-sort-list.kt
1 parent5dd4175 commit9acaf25

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎kotlin/0147-insertion-sort-list.kt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
classSolution {
2+
funinsertionSortList(head:ListNode?):ListNode? {
3+
val dummy=ListNode(0)
4+
dummy.next= head
5+
var prev= head
6+
var cur= head?.next
7+
8+
while (cur!=null) {
9+
if (prev!=null&& cur.value>= prev.value) {
10+
prev= cur
11+
cur= cur.next
12+
continue
13+
}
14+
15+
var temp= dummy
16+
while (cur.value> temp.next.value)
17+
temp= temp.next
18+
prev?.next= cur.next
19+
cur.next= temp.next
20+
temp.next= cur
21+
cur= prev?.next
22+
}
23+
24+
return dummy.next
25+
}
26+
27+
valListNode.value
28+
get()=this.`val`
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp