当前位置:网站首页>《剑指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; } };
边栏推荐
- Finally, someone finished all the dynamic planning, linked list, binary tree and string required for the interview
- 初探STM32掉电复位PDR
- 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
- Web页面table表格,实现快速筛选
- 事务_基本演示和事务_默认自动提交&手动提交
- Detailed explanation of Telnet remote login AAA mode [Huawei ENSP]
- TCC
- Tencent two sides: @bean and @component are used in the same class, what will happen?
- How to do well in enterprise system vulnerability assessment
- Notice on printing and distributing the Interim Measures for the administration of green manufacturing pilot demonstration of Shenzhen Bureau of industry and information technology
猜你喜欢

Lecture 4: Longest ascending substring
USB接口电磁兼容(EMC)解决方案

If we were the developer responsible for repairing the collapse of station B that night

腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?

【ManageEngine】什么是SIEM

Dialog manager Chapter 3: create controls

Graphic SQL of giant image

TL431-2.5v基准电压芯片几种基本用法

对话框管理器第三章:创建控件

Zhou Hongyi: if the digital security ability is backward, it will also be beaten
随机推荐
Tencent two sides: @bean and @component are used in the same class, what will happen?
Nefu117 number of prime numbers [prime number theorem]
Is it safe for Guosen Securities to open a mobile account? Is Zhongshan securities reliable
The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
How to help enterprises optimize office management
LeetCode 1143. 最长公共子序列 动态规划/medium
两阶段提交与三阶段提交
FPGA timing constraint sharing 04_ Output delay constraint
TL431-2.5v基准电压芯片几种基本用法
lc marathon 7.26
ADB command (install APK package format: ADB install APK address package name on the computer)
Jmeter录制接口自动化
网络设备硬核技术内幕 路由器篇 19 DPDK(四)
Graphical SQL is too vivid
idea打jar包与引入jar包
Notice of Nanshan District Civil Affairs Bureau on carrying out the grade evaluation of social organizations in Nanshan District in 2022
web上构建3d效果 基于three.js的实例
STM32F103C8T6在Arduino框架下驱动SH1106 1.3“ IIC OLED显示
[Yunxiang book club issue 13] multimedia processing tool ffmpeg tool set
IJCAI 2022杰出论文公布,大陆作者中稿298篇拿下两项第一