leetcode刷题_PYTHON(21):链表(21) 反转链表



class Solution: def reverseList(self, head: ListNode) -> ListNode: #空链表 if not head: return None #1节点链表 elif not head.next: return head #多节点链表 else: p = head.next q = p head.next = None while q.next: q = q.next p.next = head head = p p = q q.next = head head = q return head 作者:liyueqiang 链接:https://leetcode-cn.com/problems/reverse-linked-list/solution/shuang-zhi-zhen-jie-jue-fan-xiang-lian-b-ndtl/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/15259918.html

浙公网安备 33010602011771号