middle-of-the-linked-list
This commit is contained in:
parent
6b0e32d66a
commit
a33c19f2cc
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue