当前位置:网站首页>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;
// }
// }边栏推荐
猜你喜欢

一文理解分布式开发中的服务治理

Verilog 加法器设计

一级建造师从业者面试需要注意什么问题?

普洛斯荣获两项“数据中心绿色等级评估”5A级认证

HMS Core audio editing service audio source separation and spatial audio rendering, helping to quickly enter the world of 3D audio

Add a logo to the upper left corner of the picture, add time and address to the lower left corner, and wrap the line when the address reaches the specified length

GBASE 8s 数据库的智能大对象备份

php反序列化结构知识点实例分析

Numpy array processing (2)
一、HikariCP源码分析之获取连接流程一
随机推荐
对不起,你很难赚到中年人的钱
官宣!苏州吴江开发区上线电子劳动合同平台
Add a logo to the upper left corner of the picture, add time and address to the lower left corner, and wrap the line when the address reaches the specified length
GBASE 8s 数据索引
新手如何写专利?
applet preview pdf
Sorry, it's hard for you to earn middle-aged money
线性回归的多种实现方式
小程序微信定位不准
爽朗的一天
HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
CNCF Keith Chan:分布式云时代,云原生社区的发展与趋势
GBASE 8s 自定义存储过程和函数示例
给图片左上角加logo标识、左下角加时间和地址、地址到达指定长度换行
iNFTnews | 福布斯的Web3探索
Official announcement!Suzhou Wujiang Development Zone launches electronic labor contract platform
OPEN数据 | 新库上线 | CnOpenDataA股上市公司社会责任报告数据
GBASE 8s 自动删除正在被使用的数据库
新库上线 | CnOpenData租赁和商务服务业工商注册企业基本信息数据
模型评价指标汇总(持续更新)