carloscn / carloscn/structstudy
leetcode160:相交链表(intersection-of-two-linked-lists)
- Dominant language
- C
- Stars
- 4
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
### 问题描述:
给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 null 。
图示两个链表在节点 c1 开始相交:

题目数据 保证 整个链式结构中不存在环。
注意,函数返回结果后,链表必须 保持其原始结构 。
----------------------------------------------------------
示例一:

输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3
输出:Intersected at '8'
解释:相交节点的值为 8 (注意,如果两个链表相交则不能为 0)。
从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,6,1,8,4,5]。
在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。
— 请注意相交节点的值不为 1,因为在链表 A 和链表 B 之中值为 1 的节点 (A 中第二个节点和 B 中第三个节点) 是不同的节点。换句话说,它们在内存中指向两个不同的位置,而链表 A 和链表 B 中值为 8 的节点 (A 中第三个节点,B 中第四个节点) 在内存中指向相同的位置。
----------------------------------------------------------
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/intersection-of-two-linked-lists
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.