LeetCode : Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.
For example, the following two linked lists:
A: a1 → a2
↘
c1 → c2 → c3
↗
B: b1 → b2 → b3
begin to intersect at node c1.
/*** Definition for singly-linked list.* struct ListNode {* int val;* ListNode *next;* ListNode(int x) : val(x), next(NULL) {}* };*/
class Solution {
public:ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {ListNode* p = headA,*q = headB;while(p!=q){p = p?p->next:headB;q = q?q->next:headA;}return p;}
};
转载于:https://www.cnblogs.com/chankeh/p/6850057.html
LeetCode : Intersection of Two Linked Lists相关推荐
- [LeetCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- LeetCode Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- leetcode. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- Leetcode:Intersection of Two Linked Lists
题目大意:找两个链表的第一个交点. 这里先给出一些链表相交基础的说明: 对于链表X,用X[i]表示链表X的第i个元素,L(X)表示X的长度. 性质1:如果X[i]等于Y[j],那么可以推出X[i+1] ...
- LeetCode(160): Intersection of Two Linked Lists
Intersection of Two Linked Lists: Write a program to find the node at which the intersection of two ...
- [LeetCode]--160. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- C#LeetCode刷题之#160-相交链表(Intersection of Two Linked Lists)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3824 访问. 编写一个程序,找到两个单链表相交的起始节点. 例如 ...
- leetcode python3 简单题160. Intersection of Two Linked Lists
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百六十题 (1)题目 英文: Write a program to find t ...
- 【leetcode】Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
最新文章
- CCNA基础 IP地址子网划分
- AndoridSQLite数据库开发基础教程(9)
- Visual Studio Code之常备快捷键
- 如何确定固定资产入账价值
- 用户 IP,里面藏了多少秘密?
- android sqlite alert table,android sqlite数据库操作
- 使用visual studio 2013读取.mat文件
- matlab 积分进阶教程,matlab进阶微积分篇6
- 强联通分量:Tarjan缩点
- 正则表达式与自动机c语言,用有限自动机实现正则表达式的匹配
- Windows Server 2012R2 虚拟专用网络技术
- 电影的幕布效果怎么做?
- java dispatch_Dispatch 方法
- C/C++ tip: How to detect the operating system type using compiler predefined macros
- 已有一个已排好序的数组,要求输入一个数后,按原来顺序的规律将它插入数组中。
- 小甲鱼C++快速入门——第四天
- 最新广告法规定禁用词汇,不幸被通报,官网小伙伴们记得文案检查下哈
- 英语Aeroides海蓝宝石aeroides单词
- 用OpenSSL做自签名的证书(by quqi99)
- 团队合作,帮助他人的方式
热门文章
- 幼儿园案例经验迁移_共教研,促成长阳光天健城幼儿园9月份教研分享
- 地图选择器怎么用_简易数据分析 15 | Web Scraper 高级用法——CSS 选择器的使用....
- 最新型号设备信息对照表_所有iPhone设备都可能被解锁!黑客发布新款越狱软件“Unc0ver”...
- html网页跟随滚轮变化,实现桌面和移动浏览器元素随页面滚动产生动画
- 无法将W ndOWs配置为在,配置Wndows2000中的磁盘配额.doc
- c语言贪心算法合并箭,贪心算法:用最少数量的箭引爆气球
- 职务作品的著作权归属情况分析
- 【Java程序设计】数组
- 为什么表数据删掉一半,表文件大小不变?
- idea调试代码步入用法