day9-链表练习题力扣206
思路: 伪代码:
while(head != null and head.next != null):
dnext = dummy.next
hnext = head.next
dummy.next = hnext
head.next = hnext.next
hnext.next = dnext
return dummy.next
Python代码:
def reverseList(self, head: ListNode) -> ListNode:
dummy = ListNode()
dummy.next = head
while head != None and head.next != None:
dnext = dummy.next
hnext = head.next
dummy
共有 0 条评论