Skip to content

Commit 26382bf

Browse files
authored
Merge pull request #3177 from ashishsingh1508/patch-2
Create 0147-insertion-sort-list.go
2 parents 824a14b + 28644e0 commit 26382bf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

go/0147-insertion-sort-list.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* type ListNode struct {
4+
* Val int
5+
* Next *ListNode
6+
* }
7+
*/
8+
func insertionSortList(head *ListNode) *ListNode {
9+
dummy := new(ListNode)
10+
for head != nil {
11+
cur := dummy
12+
for ; cur.Next != nil && cur.Next.Val < head.Val; cur = cur.Next {
13+
}
14+
cur.Next, head.Next, head = head, cur.Next, head.Next
15+
}
16+
return dummy.Next
17+
}

0 commit comments

Comments
 (0)