Reverse a Linked List
Problem
Thought Process
Solution
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
current, previous, nextP = head, None, None
while current:
nextP = current.next
current.next = previous
previous = current
current = nextP
return previous
#Time: O(n)
#Space: O(1)Last updated