赞
踩
题目:
题解:
- # 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]:
- newHead = ListNode(0)
- newHead.next = None
- h = head
- while h:
- cur = ListNode(h.val)
- cur.next = newHead.next
- newHead.next = cur
- h = h.next
-
- return newHead.next
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。