206. Reverse Linked List
solution
class Solution:
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
if head is None or head.next is None:
return head
pre = None
cur = head
while cur is not None:
tmp = cur.next
cur.next = pre
pre = cur
cur = tmp
return prefollow up
Last updated