leetcode
This commit is contained in:
19
leetcode/206.py
Normal file
19
leetcode/206.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user