Arduino ESP32终极指南:5分钟搭建物联网开发环境
2026/7/18 7:07:19
时隔1年,继续力扣刷起来。
160 相交链表
class Solution: def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> Optional[ListNode]: p,q=headA,headB; while p is not q: p=p.next if p else headB; q=q.next if q else headA; return p;206 反转链表
判断 head is None 是为了兼容一开始链表就是空的情况
递归
class Solution: def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: if head is None or head.next is None: return head; rev_head=self.reverseList(head.next); tail=head.next; tail.next=head; head.next=None; return rev_head;