LeetCode Entry
876. Middle of the Linked List
fun middleNode(head: ListNode?, fast: ListNode? = head): ListNode? =
876. Middle of the Linked List easy
https://t.me/leetcode_daily_unstoppable/42
fun middleNode(head: ListNode?, fast: ListNode? = head): ListNode? =
if (fast?.next == null) head else middleNode(head?.next, fast?.next?.next)
- one-liner, but in the interview (or production) I would prefer to write a loop
Space: O(n), Time: O(n)