def reverse_list(head):
if not head or not head.next:<EOL><INDENT>return head<EOL><DEDENT>prev = None<EOL>while head:<EOL><INDENT>current = head<EOL>head = head.next<EOL>current.next = prev<EOL>prev = current<EOL><DEDENT>return prev<EOL>
:type head: ListNode
:rtype: ListNode