当前位置:网站首页>13、哈希表——两个链表第一个公共节点
13、哈希表——两个链表第一个公共节点
2022-07-28 09:58:00 【[email protected]】
- 题目描述
输入:[1,2,3,5,7,8,9]与[0,10,5,7,8,9]
输出:[5]
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
Set<ListNode> visited = new HashSet<ListNode>();
ListNode temp = headA;
while(temp != null){
visited.add(temp);
temp = temp.next;
}
temp = headB;
while(temp != null){
if(visited.contains(temp)){
return temp;
}
temp = temp.next;
}
return null;
}
首先想到的是用哈希表,但是时间复杂率略高,还有待优化。
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124785446
边栏推荐
- In retaliation for the dismissal of the company, I changed all code comments of the project!
- 19. 删除链表的倒数第 N 个结点
- 记录一次idea中的父子项目修改project与module名称,亲测!
- 医药行业数字化建设,箭在弦上
- 剑指offer
- Flink - checkpoint Failure reason: Not all required tasks are currently running
- 13 probability distributions that must be understood in deep learning
- select如果不加order by子句,返回结果的顺序是不可靠的
- 关于软考高级要不要报班学习
- On July 13, 2021, we collapsed like this
猜你喜欢

What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system

In the era of home health diagnosis, Senzo creates enhanced lateral flow test products

软件设计师考前20问,注意啦!!

ES(8.1)认证题目

为报复公司解雇,我更改了项目的所有代码注释!

Boss: there are too many systems in the company. Can we realize account interworking?

What are the advantages of MRO purchasing website for industrial products? One article will help you understand

图解 3 种主流企业架构模式(建议收藏!)

Flink - checkpoint Failure reason: Not all required tasks are currently running

Joint search set
随机推荐
每天在岗不足8小时被辞?腾讯前员工追讨1300万加班费等,法院终审获赔9万
Voice chat app - how to standardize the development process?
21. 合并两个有序链表
语音聊天app——如何规范开发流程?
[ESP32][esp-idf] AP+STA实现无线桥接 中转wifi信号
排序——快速排序(快慢指针实现)
Redis面试题必知必会
Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
2021-10-13arx
Data can't lie. Plato farm is the leader of the meta universe
13 probability distributions that must be understood in deep learning
Platofarm has made continuous progress, and has launched the official version and super primitive NFT successively
In the era of home health diagnosis, Senzo creates enhanced lateral flow test products
[esp32][esp idf] esp32s3 quickly build lvglv7.9
matlab特征点提取--记录自用
IE兼容性问题处理
二维前缀和
Etcd (highly available kV database)
2021.07.13 我们是这样崩的
LIBCMTD.lib