MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / reorderList

Function reorderList

reorder_list_143/solution.go:5–27  ·  view source on GitHub ↗
(head *ListNode)

Source from the content-addressed store, hash-verified

3import . "github.com/austingebauer/go-leetcode/structures"
4
5func reorderList(head *ListNode) {
6 if head == nil || head.Next == nil {
7 return
8 }
9
10 cur := head
11 var end *ListNode
12 for end != cur {
13 end = head
14
15 // move e until one before the end
16 for end.Next != nil && end.Next.Next != nil {
17 end = end.Next
18 }
19
20 if end != cur {
21 end.Next.Next = cur.Next
22 cur.Next = end.Next
23 end.Next = nil
24 cur = cur.Next.Next
25 }
26 }
27}

Callers 1

Test_reorderListFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_reorderListFunction · 0.68