#206
Reverse Linked List
easy· Linked Listruns: 0Given the head of a singly linked list, reverse the list and return the new head.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 281
class Solution:
def reverseList(self, head: ListNode | None) -> ListNode | None:
prev = None
curr = head
while curr:
next_node = curr.next
curr.next = prev
prev = curr
curr = next_node
return prev
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.