Leetcode Note: Go - Middle of the Linked List
Middle of the Linked List - LeetCode
https://leetcode.com/problems/middle-of-the-linked-list/
- Go 言語で取り組んだメモ
所感
- linked list が渡されるので先頭と末尾以外の要素を return する
回答
[Go] [Fun] One-Liner to find the Linked List middle - LeetCode Discuss
https://leetcode.com/problems/middle-of-the-linked-list/discuss/961151/Go-Fun-One-Liner-to-find-the-Linked-List-middle
func middleNode(head *ListNode) *ListNode {
for fast := head; fast != nil && fast.Next != nil; fast, head = fast.Next.Next, head.Next {}
return head
}