Open fockspaces opened 11 months ago
# 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]: cur = head new_head = None while cur: next_node = cur.next cur.next = new_head new_head = cur cur = next_node return new_head