当前位置:网站首页>《剑指Offer》两个链表的第一个公共结点
《剑指Offer》两个链表的第一个公共结点
2022-07-27 14:15:00 【傻子是小傲娇】
题目描述
输入两个链表,找出它们的第一个公共结点。
长度相同有公共结点,第一次就遍历到;
没有公共结点,走到尾部NULL相遇,返回NULL长度不同有公共结点,第一遍差值就出来了,第二遍一起到公共结点;
没有公共,第二次一起到结尾NUL
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2) { ListNode *p1 = pHead1; ListNode *p2 = pHead2; while (p1 != p2){ p1 = (p1 == nullptr ? pHead1 : p1->next); p2 = (p2 == nullptr ? pHead2 : p2->next); } return p1; } };
边栏推荐
- What is tor? What is the use of tor browser update?
- Differences among CPU, GPU and NPU
- FPGA timing constraint sharing 04_ Output delay constraint
- lc marathon 7.26
- Code coverage statistical artifact -jacobo tool practice
- MOS管防止电源反接的原理
- 网络设备硬核技术内幕 路由器篇 6 汤普金森漫游网络世界(中)
- cap理论和base理论
- An example of building 3D effects on the web based on three.js
- 代码覆盖率统计神器-jacoco工具实战
猜你喜欢

【WORK】关于技术架构

Nokia's patent business was hit for the first time, and Chinese enterprises are not so easy to knead

谷歌团队推出新Transformer,优化全景分割方案|CVPR 2022

LeetCode 781. 森林中的兔子 哈希表/数学问题 medium

Differences among CPU, GPU and NPU

LeetCode 240. 搜索二维矩阵 II medium

Skywalking distributed system application performance monitoring tool - medium

周鸿祎:数字安全能力落后也会挨打

Kubernetes CNI 分类/运行机制

关于 CMS 垃圾回收器,你真的懂了吗?
随机推荐
ad7606与stm32连接电路介绍
网络设备硬核技术内幕 路由器篇 6 汤普金森漫游网络世界(中)
Tencent two sides: @bean and @component are used in the same class, what will happen?
Jmeter录制接口自动化
LeetCode 783. 二叉搜索树节点最小距离 树/easy
[ManageEngine] what is Siem
DIY制作示波器的超详细教程:(一)我不是为了做一个示波器
泛型
关于 CMS 垃圾回收器,你真的懂了吗?
Timestamp of AAC, h264, etc
同花顺开户在手机开户安全吗?
事务_基本演示和事务_默认自动提交&手动提交
Zhou Hongyi: if the digital security ability is backward, it will also be beaten
MySQL 面试40连问,面试官你再问下去我可要翻脸了
被动收入:回归原始且安全的两种赚取方法
Nefu117 number of prime numbers [prime number theorem]
Data warehouse project is never a technical project
DirectX 入门知识
adb命令 (安装apk包格式:adb install 电脑上apk地址包名)
JUC(JMM、Volatile)