当前位置:网站首页>The first common node of the two linked lists of "Jianzhi offer"
The first common node of the two linked lists of "Jianzhi offer"
2022-07-27 15:14:00 【A fool is a little proud】
Title Description
Enter two linked lists , Find their first common node .
There are common nodes with the same length , The first time I traverse ;
There are no public nodes , Go to the end NULL meet , return NULLDifferent lengths have common nodes , The difference comes out the first time , Go to the public node together for the second time ;
No public , The second time together to the end 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; } };
边栏推荐
- 一些二进制位操作
- OBS advanced DXGI acquisition screen process, and how to modify it to its own cursor
- Unity最简洁的对象池实现
- NEFU117 素数个数的位数【素数定理】
- What is the breakthrough point of digital transformation in the electronic manufacturing industry? Lean manufacturing is the key
- 南山区民政局关于开展2022年度南山区社会组织等级评估工作的通知
- Unity性能优化------渲染优化(GPU)之LOD(Level of detail)
- NEFU118 n! How many zeros are there after [basic theorem of arithmetic]
- 网络设备硬核技术内幕 路由器篇 20 DPDK (五)
- 《剑指Offer》 链表反转
猜你喜欢

Why is there no unified quotation for third-party testing fees of software products?

Stm32f103c8t6 drives sh1106 1.3 "IIC OLED display under Arduino frame

什么是Tor?Tor浏览器更新有什么用?

Unity性能优化------渲染优化(GPU)之Occlusion culling(遮挡剔除)

修改frameworks资源文件如何单编

Basic usage of kotlin

Idea makes jar packages and introduces jar packages

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

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

适配验证新职业来了!华云数据参与国家《信息系统适配验证师国家职业技能标准》编制
随机推荐
DIY制作示波器的超详细教程:(一)我不是为了做一个示波器
仪表放大器和运算放大器优缺点对比
修改frameworks资源文件如何单编
Understand the evolution of redis architecture in one article
网络设备硬核技术内幕 路由器篇 18 DPDK及其前传(三)
Unity 鼠标控制第一人称摄像机视角
《剑指Offer》剪绳子
adb命令 (安装apk包格式:adb install 电脑上apk地址包名)
Graphical SQL is too vivid
STM32之CAN ---CAN ID过滤器分析
Data warehouse project is never a technical project
一些二进制位操作
代码覆盖率统计神器-jacoco工具实战
网络设备硬核技术内幕 路由器篇 5 汤普金森漫游网络世界(上)
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
internship:其他配置类的编写
Jmeter录制接口自动化
Principle of MOS tube to prevent reverse connection of power supply
分布式锁
LeetCode 1143. 最长公共子序列 动态规划/medium