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
}