Terrible LeetCode in Kotlin: #876 Middle of the Linked List

44 Просмотры
Издатель
Another day, another LeetCode question (for now). Today, I'm running through #876 on LeetCode, Middle of the Linked List. The input provides a root node within a linked list and asks for the node reference of the middle of the singly linked list. This one wasn't too bad for me and used one of the patterns that I am more familiar with. At the end of the day, I used 2 pointers - one of which moved twice as fast as the other - with the underlying logic being that when the pointer that moves twice as fast reaches the end of the list, the slower pointer will be perfectly in the middle (or the 2nd of two middle nodes).

I work in Kotlin as my LeetCode programming language because my current focus is on Android app development. Kotlin is interoperable with Java, so the solution should be relatively similar albeit with some more boilerplate checks for nulls and such.

Current Grind:
- Grind75 list, 22 weeks/7 hours per week, [23/169]
(https://www.techinterviewhandbook.org/grind75)

Chapters:
00:00 - Opening, final solution (2 pointers)
Категория
Язык программирования Kotlin
Комментариев нет.