class ListNode(var value: Int) { var next: ListNode? = null }
fun reverseList(head: ListNode?): ListNode? { var prev: ListNode? = null var current = head while (current != null) { val nextNode = current.next current.next = prev prev = current current = nextNode }
return prev
|