1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00
LeetCode/go/middle-of-the-linked-list.go

21 lines
275 B
Go
Raw Normal View History

package main
/**
* 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
}