当前位置:网站首页>13. Hash table - the first common node of two linked lists
13. Hash table - the first common node of two linked lists
2022-07-28 10:17:00 【[email protected]】
- Title Description
Input :[1,2,3,5,7,8,9] And [0,10,5,7,8,9]
Output :[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;
}
The first thought is to use hash table , But the time complexity is slightly higher , It needs to be optimized .
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958223948.html
边栏推荐
猜你喜欢
随机推荐
Differences among pipes, pipe passes and pipe States
[esp32][esp idf] esp32s3 quickly build lvglv7.9
Leetcode076 -- the kth largest number in the array
胡润发布2020中国芯片设计10强民营企业:华为海思竟然没有上榜!
02.1.2.逻辑类型 bool
uni-app进阶之生命周期
5、动态规划---斐波那契数列
海量数据TopN问题
2021-10-13arx
Skillfully use NGX_ Lua makes traffic grouping
【云驻共创】企业数字化转型,华为云咨询与你同行
Thinking and summary of technical personnel | R & D Efficiency
Sort - quick sort (fast and slow pointer Implementation)
Summary of key points of bank entry examination
13 probability distributions that must be understood in deep learning
QT | some summaries of signals and slots
SuperMap iServer发布管理以及调用地图服务
Uni app advanced life cycle
印度计划禁用中国电信设备!真离得开华为、中兴?
13、哈希表——两个链表第一个公共节点









![[jzof] 14 cut rope](/img/36/6f58b443a549ad245c1c4cfe5d13af.png)