Files
PS/leetcode/206.py
Gyubin Han dede0dca01 leetcode
2025-02-19 14:09:55 +09:00

20 lines
509 B
Python

# 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]:
l=[]
while not head==None:
n=ListNode(head.val)
l.append(n)
head=head.next
r=ListNode()
rt=r
while len(l)>0:
rt.next=l.pop()
rt=rt.next
return r.next