go: add «876. Middle of the Linked List»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
2d4ba86cbe
commit
f65d94b769
1 changed files with 20 additions and 0 deletions
20
go/middle-of-the-linked-list.go
Normal file
20
go/middle-of-the-linked-list.go
Normal 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
|
||||
}
|
Loading…
Reference in a new issue