middle-of-the-linked-list

This commit is contained in:
Gleb Koval 2021-11-09 15:56:54 +00:00
parent 6b0e32d66a
commit a33c19f2cc
No known key found for this signature in database
GPG Key ID: DF27F6A77C48FDA0
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package main
type ListNode struct {
Val int
Next *ListNode
}
func middleNode(head *ListNode) *ListNode {
mid, end := head, head
for c := 0; end != nil; c++ {
end = end.Next
if c%2 == 1 {
mid = mid.Next
}
}
return mid
}