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相关推荐

  1. [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 ...

  2. 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 ...

  3. 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 ...

  4. Leetcode:Intersection of Two Linked Lists

    题目大意:找两个链表的第一个交点. 这里先给出一些链表相交基础的说明: 对于链表X,用X[i]表示链表X的第i个元素,L(X)表示X的长度. 性质1:如果X[i]等于Y[j],那么可以推出X[i+1] ...

  5. 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 ...

  6. [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 ...

  7. C#LeetCode刷题之#160-相交链表(Intersection of Two Linked Lists)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3824 访问. 编写一个程序,找到两个单链表相交的起始节点. 例如 ...

  8. leetcode python3 简单题160. Intersection of Two Linked Lists

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百六十题 (1)题目 英文: Write a program to find t ...

  9. 【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 ...

最新文章

  1. CCNA基础 IP地址子网划分
  2. AndoridSQLite数据库开发基础教程(9)
  3. Visual Studio Code之常备快捷键
  4. 如何确定固定资产入账价值
  5. 用户 IP,里面藏了多少秘密?
  6. android sqlite alert table,android sqlite数据库操作
  7. 使用visual studio 2013读取.mat文件
  8. matlab 积分进阶教程,matlab进阶微积分篇6
  9. 强联通分量:Tarjan缩点
  10. 正则表达式与自动机c语言,用有限自动机实现正则表达式的匹配
  11. Windows Server 2012R2 虚拟专用网络技术
  12. 电影的幕布效果怎么做?
  13. java dispatch_Dispatch 方法
  14. C/C++ tip: How to detect the operating system type using compiler predefined macros
  15. 已有一个已排好序的数组,要求输入一个数后,按原来顺序的规律将它插入数组中。
  16. 小甲鱼C++快速入门——第四天
  17. 最新广告法规定禁用词汇,不幸被通报,官网小伙伴们记得文案检查下哈
  18. 英语Aeroides海蓝宝石aeroides单词
  19. 用OpenSSL做自签名的证书(by quqi99)
  20. 团队合作,帮助他人的方式

热门文章

  1. 幼儿园案例经验迁移_共教研,促成长阳光天健城幼儿园9月份教研分享
  2. 地图选择器怎么用_简易数据分析 15 | Web Scraper 高级用法——CSS 选择器的使用....
  3. 最新型号设备信息对照表_所有iPhone设备都可能被解锁!黑客发布新款越狱软件“Unc0ver”...
  4. html网页跟随滚轮变化,实现桌面和移动浏览器元素随页面滚动产生动画
  5. 无法将W ndOWs配置为在,配置Wndows2000中的磁盘配额.doc
  6. c语言贪心算法合并箭,贪心算法:用最少数量的箭引爆气球
  7. 职务作品的著作权归属情况分析
  8. 【Java程序设计】数组
  9. 为什么表数据删掉一半,表文件大小不变?
  10. idea调试代码步入用法