1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/go/middle-of-the-linked-list.go
Matej Focko f65d94b769
go: add «876. Middle of the Linked List»
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-03-07 23:00:05 +01:00

20 lines
296 B
Go

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