Reverse Linked List

Linked List
Easy

Approach

Diagrams

Analysis

Time

O(n)

Space

O(1)
class Solution:
    def reverseList(self, head):
        prev, cur, next = None, head, None

        while cur is not None:
            next = cur.next

            cur.next = prev

            prev = cur
            cur = next

        return prev

Learn

#Linked List

Videos