leetcode-006 detect cycle
package leetcode;
public class DetectCycle {
public ListNode detectCycle(ListNode head) {
ListNode s=head;
ListNode f=head;
while(f!=null&&f.next!=null){
s=s.next;
f=f.next.next;
if(s==f){
break;
}
}
if(f==null||f.next==null)
return null;
s=head;
while(s!=f){
s=s.next;
f=f.next;
}
return s;
}
}
leetcode-006 detect cycle的更多相关文章
- Leetcode: Graph Valid Tree && Summary: Detect cycle in undirected graph
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- LeetCode Linked List Cycle II 和I 通用算法和优化算法
Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no cyc ...
- Leetcode 520. Detect Capital 发现大写词 (字符串)
Leetcode 520. Detect Capital 发现大写词 (字符串) 题目描述 已知一个单词,你需要给出它是否为"大写词" 我们定义的"大写词"有下 ...
- Geeks - Detect Cycle in a Directed Graph 推断图是否有环
Detect Cycle in a Directed Graph 推断一个图是否有环,有环图例如以下: 这里唯一注意的就是,这是个有向图, 边组成一个环,不一定成环,由于方向能够不一致. 这里就是添加 ...
- Detect cycle in a directed graph
Question: Detect cycle in a directed graph Answer: Depth First Traversal can be used to detect cycle ...
- [LeetCode] Linked List Cycle II 单链表中的环之二
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
- [LeetCode] Linked List Cycle 单链表中的环
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...
- [LeetCode]Linked List Cycle II解法学习
问题描述如下: Given a linked list, return the node where the cycle begins. If there is no cycle, return nu ...
- LeetCode——Linked List Cycle
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using ex ...
- LeetCode——Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
随机推荐
- Viewpager实现图片轮播
//-------------主布局文件------------------------------------- <LinearLayout xmlns:android="http: ...
- Android中自定义veiw使用Java中的回调方法
//------------------MainActivity----中---------------------------------- import android.os.Bundle;imp ...
- redhat安装wine
在基于RedHat或Debian的系统上安装 Wine 1.7 原创:LCTT https://linux.cn/article-3723-1.html Wine,Linux上最流行也是最有力的软件, ...
- c++数组指针bug
ClassA* csList = ]; ClassA ca = csList[]; ca.x=; CCLOG(].x);//output: caList[0].x -431602080.000000 ...
- Dev之ChartControl控件(二)— 绘制多重坐标图形
有时针对一个ChartControl控件可能要设置多个Y轴,进行显示: 以下举个例子:如在一个Chart中显示多个指标项如图: 首先,读取数据,并对左边的Y轴最大和最小值进行设定 IndexSerie ...
- HDU 2609 How many
最小表示法+Map或者字典树,最小表示法找了个模板,还没学习呢... #include<cstdio> #include<cstring> #include<cmath& ...
- HTNL5新增标签
我们来看一下HTML 5提供的一些新的标签用法以及和HTML 4的区别. <article>标签定义外部的内容.比如来自一个外部的新闻提供者的一篇新的文章,或者来自 blog 的文本,或者 ...
- CABasicAnimation 基础
一.CABasicAnimation CAPropertyAnimation的子类 属性解析: fromValue:keyPath相应属性的初始值 toValue:keyPath相应属性的结束值 随着 ...
- 通过ant调用shell脚本执行adb命令
在Hudson或者Jenkins中利用ant的exec 来调用shell命令,通过shell脚本来执行adb shell命令,可以正常执行,不会出现在ant中直接调用adb shell出现的假死情况. ...
- 原创:LoadTest系列之Insert Condition
当脚本中的部分内容需要满足某些条件后才执行时,则可以使用Insert Condition,例如有如下操作: 操作1:登录 操作2:添加一条数据: 在这两个操作中,只有操作1成功后,操作2才有意义,这时 ...