1 先让长的链表先走,然后相同长度下看是否相遇 classSolution(object):defgetIntersectionNode(self, headA, headB):""":type head1, head1: ListNode :rtype: ListNode"""ifnotheadAornotheadB:returnNonedefcal(head): count=0whilehead: count+= 1head=head.nextreturncount countA=cal(headA) countB=c...
Odd.next= dummyeven#因为无论even=None还是Even.next=None,其实在没有Even = Even.next之前,Even.next=head链中它的下一个,所以不用分类讨论加不加Nonereturnhead 错误原因:Even节点变化之后,Odd取next和.next.next时,链表都已经变化了 参考:保证链表取值过程中相对顺序不乱! #Definition for singly-linked li...
packagetest.linked; /*** 移除 链表中的某一个值* 链表操作中,可以使用原链表来直接进行删除操作,也可以设置一个虚拟头结点在进行删除操作,接下来看一看哪种方式更方便。* 力扣题目链接:https://leetcode-cn.com/problems/remove-linked-list-elements/* <p...
基础的数据结构(总览):https://github.com/azl397985856/leetcode/blob/master/thinkings/basic-data-structure.md [3] 几乎刷完了力扣所有的链表题,我发现了这些东西:https://lucifer.ren/blog/2020/11/08/linked-list/ [4] 几乎刷完了力扣所有的树题,我发现了这些东西:https://l...
mycode 95% #Definition for a binary tree node.#class TreeNode(object):#def __init__(self, x):#self.val = x#self.left = None#self.right = NoneclassSolution(object):definorderTraversal(self, root):""":type root: TreeNode :rtype: List[int]"""ifnotroot:return[] ...