LeetCode Entry

876. Middle of the Linked List

5.12.2022 easy 2022 kotlin

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)