File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change
1
+ *** 给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 null 。***
2
+
3
+ ```
4
+ # Definition for singly-linked list.
5
+ # class ListNode:
6
+ # def __init__(self, x):
7
+ # self.val = x
8
+ # self.next = None
9
+
10
+ class Solution:
11
+ def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
12
+ #两个人速度一致, 走过的路程一致。那么肯定会同一个时间点到达终点。如果到达终点的最后一段路两人都走的话,那么这段路上俩人肯定是肩并肩手牵手的。
13
+ A,B=headA,headB
14
+ while A!=B:
15
+ A = A.next if A else headB
16
+ B = B.next if B else headA
17
+ return A
18
+ ```
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ LeetCode 精选算法题, Python题解+详细注释,持续更新。
45
45
- [ 25. 颜色分类] ( https://github.com/jasoncao11/Algorithm-notebook/blob/master/25.%20%E9%A2%9C%E8%89%B2%E5%88%86%E7%B1%BB.md )
46
46
- [ 30. 合并两个有序数组] ( https://github.com/jasoncao11/Algorithm-notebook/blob/master/30.%20%E5%90%88%E5%B9%B6%E4%B8%A4%E4%B8%AA%E6%9C%89%E5%BA%8F%E6%95%B0%E7%BB%84.md )
47
47
- [ 41. 反转链表] ( https://github.com/jasoncao11/Algorithm-notebook/blob/master/41.%20%E5%8F%8D%E8%BD%AC%E9%93%BE%E8%A1%A8.md )
48
+ - [ 51. 环形链表] ( https://github.com/jasoncao11/Algorithm-notebook/blob/master/51.%20%E7%8E%AF%E5%BD%A2%E9%93%BE%E8%A1%A8.md )
48
49
49
50
### 5. 回溯
50
51
You can’t perform that action at this time.
0 commit comments