You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LeetCode link: [160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists), difficulty: **Easy**.
4
3
5
-
[中文题解](#中文题解)
6
-
7
-
## LeetCode problem description
4
+
## Description of "160. Intersection of Two Linked Lists"
8
5
Given the heads of two singly linked-lists `headA` and `headB`, return _the node at which the two lists intersect_. If the two linked lists have no intersection at all, return `null`.
9
6
10
7
For example, the following two linked lists begin to intersect at node `c1`:
@@ -15,8 +12,6 @@ The test cases are generated such that there are **no cycles** anywhere in the e
15
12
16
13
**Note** that the linked lists must **retain their original structure** after the function returns.
17
14
18
-
Difficulty: **Easy**
19
-
20
15
### [Example 1]
21
16

22
17
@@ -25,6 +20,13 @@ Difficulty: **Easy**
25
20
**Output**: `Intersected at '8'`
26
21
27
22
### [Example 2]
23
+

24
+
25
+
**Input**: `intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4]`
26
+
27
+
**Output**: `Intersected at '2'`
28
+
29
+
### [Example 3]
28
30

29
31
30
32
**Input**: `listA = [2,6,4], listB = [1,5]`
@@ -40,8 +42,6 @@ Difficulty: **Easy**
40
42
**Follow up**: Could you write a solution that runs in `O(m + n)` time and use only `O(1)` memory?
41
43
42
44
## Intuition
43
-
[中文题解](#中文题解)
44
-
45
45
1. First calculate the number of nodes in the two linked lists A and B. The number of nodes in linked list A is `node_count_a`, and the number of nodes in linked list B is `node_count_b`.
46
46
2. If `node_count_b > node_count_a`, then perform `node = node.next` for `node_count_b - node_count_a` times on linked list B.
47
47
3. At this time, repeat `node = node.next` on the two linked lists until the same node is found or one of the linked lists has reached the end.
@@ -333,66 +333,3 @@ public class Solution
333
333
```
334
334
// Welcome to create a PR to complete the code of this language, thanks!
Given the heads of two singly linked-lists `headA` and `headB`, return _the node at which the two lists intersect_. If the two linked lists have no intersection at all, return `null`.
1. First calculate the number of nodes in the two linked lists A and B. The number of nodes in linked list A is `node_count_a`, and the number of nodes in linked list B is `node_count_b`.
46
-
2. If `node_count_b > node_count_a`, then perform `node = node.next` for `node_count_b - node_count_a` times on linked list B.
47
-
3. At this time, repeat `node = node.next` on the two linked lists until the same node is found or one of the linked lists has reached the end.
1.First calculate the number of nodes in the two linked lists A and B. The number of nodes in linked list A is `node_count_a`, and the number of nodes in linked list B is `node_count_b`.
0 commit comments