206. Reverse Linked List

Posted on Jun 8, 2025

Solution

Implementation

class Solution {
    fun reverseList(head: ListNode?): ListNode? {
        var current: ListNode? = head
        var next: ListNode? = null

        while (current != null) {
            val temp = current.next
            current.next = next
            next = current
            current = temp
        }

        return next
    }
}