Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 457 Bytes

206.reverse-linked-list.md

File metadata and controls

19 lines (15 loc) · 457 Bytes
fun reverseList(head: ListNode?): ListNode? {
    var previous: ListNode? = null
    var current: ListNode? = head

    while (current != null) {
        // We have to store the next pointer first before overriding.
        val next = current.next
        current.next = previous

        previous = current
        current = next
    }
    return previous
}