Faaez Razeen

Reverse Linked List

  • 1 min read
  • LC-Easy
  • Blind75
  • Recursion
  • Linked List

3 years ago

Approach 1: Iterative

I mean, nothing to say really. Just reverse the list.

Implementation

def reverseList(head: Optional[ListNode]) -> Optional[ListNode]: prev, curr = None, head while curr: nxt = curr.next curr.next = prev prev = curr curr = nxt return prev