当前位置:网站首页>JZ23 链表中环的入口结点
JZ23 链表中环的入口结点
2022-07-29 21:49:00 【syc596】
JZ23 链表中环的入口结点
链表中环的入口结点_牛客题霸_牛客网 (nowcoder.com)
//11
//快慢指针
import java.util.*;
public class Solution {
public ListNode EntryNodeOfLoop(ListNode head) {
if(head==null||head.next==null){
return null;
}
ListNode slow=head;
ListNode fast=head;
while(fast!=null&&fast.next!=null){
slow=slow.next;
fast=fast.next.next;
if(slow==fast){
ListNode meet=slow;
while(head!=meet){
head=head.next;
meet=meet.next;
}
return meet;
}
}
return null;
}
}
// //set
// import java.util.*;
// public class Solution {
// public ListNode EntryNodeOfLoop(ListNode head) {
// Set<ListNode> set=new HashSet<>();
// ListNode cur=head;
// while(cur!=null){
// if(set.contains(cur)){
// return cur;
// }else{
// set.add(cur);
// }
// cur=cur.next;
// }
// return null;
// }
// }边栏推荐
- 5V升压充电8.4V芯片
- Numpy array processing (2)
- 啊?现在初级测试招聘都要求会自动化了?
- One of the uses of linkedlist: Get the address of the structure variable through the address of the structure member
- 网络通信编程基础,BIO,NIO
- INFTnews | Forbes Web3 exploration
- C语言操作符详解(1)
- The world is on fire, Google servers have crashed
- GBASE 8s 通过light scan优化查询性能
- 【Verilog】Verilog设计进阶
猜你喜欢
随机推荐
华为畅享50 Pro评测:HarmonyOS加持 更流畅更安全
怎样下载国内外专利?
毕业论文文献综述写作技巧,超级详细!
applet preview pdf
官宣!苏州吴江开发区上线电子劳动合同平台
GBASE 8s 自定义存储过程和函数使用
给pdf添加已作废标识
文献综述的写作技巧,掌握这些技巧,效率大大提高!
GBASE 8s PAM插入式身份验证模块
"Introduction to nlp + actual combat: Chapter 7: Dataset loading in pytorch and the use of its own datasets"
九、HikariCP源码分析之ConcurrentBag二
CNCF Keith Chan:分布式云时代,云原生社区的发展与趋势
SQL教程之性能不仅仅是查询
qt中qstring合并字符串
【Verilog】Verilog设计进阶
GBASE 8s 通过light scan优化查询性能
03-树2 List Leaves
怎样把某个公司所有的专利全部查到、一网打尽?
Add obsolete flag to pdf
spyder打不开解决方案









