go: add «876. Middle of the Linked List»

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-03-07 23:00:05 +01:00
parent 2d4ba86cbe
commit f65d94b769
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,20 @@
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
}