当前位置:网站首页>《剑指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; } };
边栏推荐
- 移动端使用vantUI的list组件,多个tab项来回切换时,列表加载多次导致数据无法正常展示
- 网络设备硬核技术内幕 路由器篇 16 DPDK及其前传(一)
- 修改frameworks资源文件如何单编
- Visual system design example (Halcon WinForm) -10. PLC communication
- Web页面table表格,实现快速筛选
- 网络设备硬核技术内幕 路由器篇 14 从鹿由器到路由器 (中)
- 南山区民政局关于开展2022年度南山区社会组织等级评估工作的通知
- Get the data of the first frame of unity's open camera
- 网络设备硬核技术内幕 路由器篇 3 贾宝玉梦游太虚幻境 (中)
- 网络设备硬核技术内幕 路由器篇 19 DPDK(四)
猜你喜欢

What is tor? What is the use of tor browser update?

关于 CMS 垃圾回收器,你真的懂了吗?

Dynamic programming - stock trading 5

基于stm32的数字示波器设计方案

视觉系统设计实例(halcon-winform)-9.文字显示

@What happens when bean and @component are used on the same class?

USB2.0接口的EMC设计方案

Jmeter录制接口自动化

【ManageEngine】什么是SIEM

The mobile terminal uses the list component of vantui. When multiple tab items are switched back and forth, the list is loaded many times, resulting in the failure of normal display of data
随机推荐
Get the data of the first frame of unity's open camera
【WORK】关于技术架构
ad7606与stm32连接电路介绍
DirectX 入门知识
STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示
STM32 CAN 通信 滤波设置问题
Stm32f103c8t6 drives ssd1306 0.96 "IIC OLED display under Arduino frame
OBS advanced DXGI acquisition screen process, and how to modify it to its own cursor
DXGI acquisition process
Is there a regular and safe account opening platform for gold speculation
网络设备硬核技术内幕 路由器篇 5 汤普金森漫游网络世界(上)
Getting started with DirectX
网络设备硬核技术内幕 路由器篇 6 汤普金森漫游网络世界(中)
网络设备硬核技术内幕 路由器篇 15 从鹿由器到路由器 (下)
深圳市人力资源和社会保障局关于发放脱贫人口就业有关补贴的通知
The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
LeetCode 81. 搜索旋转排序数组 II 二分/medium
网络设备硬核技术内幕 路由器篇 3 贾宝玉梦游太虚幻境 (中)
OBS 进阶之 DXGI 采集屏幕流程,并如何修改为自己的光标
周鸿祎:数字安全能力落后也会挨打