feat: sunday
This commit is contained in:
34
pkg/reorder_list/main.go
Normal file
34
pkg/reorder_list/main.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package reorderlist
|
||||||
|
|
||||||
|
type ListNode struct {
|
||||||
|
Val int
|
||||||
|
Next *ListNode
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReorderList(head *ListNode) {
|
||||||
|
nodes := []*ListNode{}
|
||||||
|
for head != nil {
|
||||||
|
nodes = append(nodes, head)
|
||||||
|
head = head.Next
|
||||||
|
}
|
||||||
|
|
||||||
|
start := 0
|
||||||
|
end := len(nodes) - 1
|
||||||
|
for {
|
||||||
|
if start == end {
|
||||||
|
nodes[start].Next = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes[start].Next = nodes[end]
|
||||||
|
start++
|
||||||
|
|
||||||
|
if start == end {
|
||||||
|
nodes[end].Next = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes[end].Next = nodes[start]
|
||||||
|
end--
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user