当前位置:网站首页>剑指 Offer 52. 两个链表的第一个公共节点
剑指 Offer 52. 两个链表的第一个公共节点
2022-07-16 14:18:00 【anieoo】
原题链接:剑指 Offer 52. 两个链表的第一个公共节点
solution:
第一条路径分为a + c,第二条路径分为b + c.当A走到终点null时,跳到B起点,当B走到终点null的时候,跳到A的起点,最后相遇的时候一定都走了a + b + c的结点数
/**
* 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 *ha = headA;
ListNode *hb = headB;
while(ha != hb) {
ha = ha == NULL ? headB : ha->next;
hb = hb == NULL ? headA : hb->next;
}
return ha;
}
};边栏推荐
- Common network devices and network reference models, as well as common network layer protocols and data communication processes
- 重写equals为什么要重写hashcode
- 【golang】cannot unmarshal xxx “ into Go struct field xxx of type xxx
- WordPress personal blog theme wp-reason-v1.0
- Image xmage de Huawei: Cherchez toutes les images du monde et voyez enfin Bodhisattva
- 《遥远的救世主》遵守客观规律(六)——文化属性
- Leetcode 47. 全排列 II
- 26 top open source projects, 87 open tasks, Alibaba programming summer 2022 student registration channel opened
- Thread. Introduction to sleep
- pycuda 安装完毕,验证步骤
猜你喜欢

100% accuracy, Alibaba business travel billing system architecture design practice

【Ucos-III源码分析】——消息队列

10个第一、2个第二,达摩院NLP团队在SemEval 2022的夺冠之旅

It's decided. There are 93 open source tasks in 6 fields. Alibaba open source tutor will take you to participate in the open source summer 2022 of the Chinese Academy of Sciences

阿里达摩院TableQA技术让表格说话

Pytorch构建网络细节总结

MySQL 变量、流程控制与游标练习

MySQL 变量、流程控制与游标

ctf-pikachu-sql

MySQL超详细安装教程 手把手教你安装MySQL到使用MySQL 最简单的MySQL安装方式,这种方式装,卸载也简单
随机推荐
Your first orthodontic condition (continuously updating)
【Ucos-III源码分析】——信号量
Anaconda 的认识以及和它相关的一些编辑器的简单介绍
P1789 [MC survival] torch [introduction]
web开发从入门到精通一(详细)
IDEA安装、配置、测试
26个顶级开源项目,87个开放任务,阿里巴巴编程之夏2022学生报名通道开启
业务类库中的老门店类封装和调用
请查收,您有一份阿里先锋开源项目清单
北京华联BHG Mall持续发力,BHG DAY引领城市消费新热潮
程序分析与优化 - 11 多分支分析
常见的网路设备和网络参考模型,以及常见的网络层协议及数据通信过程
对象序列化流与反序列化流
与机器对话,阿里达摩院挑战新一代人机对话技术
[动态规划]DP20 计算字符串的编辑距离-中等
Leetcode 47. 全排列 II
uCOS-III学习笔记——时间片轮转
Kaggle文件下载(权重、推理文件...)
【Ucos-III源码分析】——内存管理机制
集合(Properties)