2024-06-16 11:44:08 +02:00
|
|
|
package main
|
2024-03-07 23:00:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Definition for singly-linked list.
|
|
|
|
* type ListNode struct {
|
|
|
|
* Val int
|
|
|
|
* Next *ListNode
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
func middleNode(head *ListNode) *ListNode {
|
|
|
|
x := head
|
|
|
|
y := head
|
|
|
|
|
|
|
|
for y != nil && y.Next != nil {
|
|
|
|
x = x.Next
|
|
|
|
y = y.Next.Next
|
|
|
|
}
|
|
|
|
|
|
|
|
return x
|
|
|
|
}
|