-
lang
kotlin
-
tags
Linked List
Two Pointers
class Solution {
fun middleNode(head: ListNode?): ListNode? {
var front = head
var back = head
// move 2step on front node
// move 1step on back node, it will stop at middle node. ( 2 : 1 )
while (front?.next != null) {
front = front?.next?.next
back = back?.next
}
return back
}
}