Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 767 Bytes

Reverse-Linked-List.md

File metadata and controls

44 lines (36 loc) · 767 Bytes
status tags Link
LC_Easy
Linked-List
NeetCode150

Finished in 2 minutes Pretty easy.

Problem name

title: Psuedo Solution
collapse: closed
- First point
- Second point

Problem statement

Solution (Optimized)

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        prev = None
        curr = head
        while curr:
            _next = curr.next
            curr.next = prev
            prev = curr
            curr = _next
        return prev