141 Linked List Cycle 环形链表
给定一个链表,判断链表中否有环。
补充:
你是否可以不用额外空间解决此题?
详见:https://leetcode.com/problems/linked-list-cycle/description/
Java实现:
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public boolean hasCycle(ListNode head) {
if(head==null){
return false;
}
ListNode slow=head;
ListNode fast=head;
while(fast!=null&&fast.next!=null){
slow=slow.next;
fast=fast.next.next;
if(slow==fast){
return true;
}
}
return false;
}
}
141 Linked List Cycle 环形链表的更多相关文章
- LeetCode 141. Linked List Cycle环形链表 (C++)
题目: Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked ...
- 141. Linked List Cycle(判断链表是否有环)
141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you sol ...
- [LeetCode] 141. Linked List Cycle 单链表中的环
Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked lis ...
- LeetCode 141. Linked List Cycle 判断链表是否有环 C++/Java
Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked lis ...
- [leetcode]141. Linked List Cycle判断链表是否有环
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...
- 【LeetCode】Linked List Cycle(环形链表)
这道题是LeetCode里的第141道题. 题目要求: 给定一个链表,判断链表中是否有环. 进阶: 你能否不使用额外空间解决此题? 简单题,但是还是得学一下这道题的做法,这道题是用双指针一个fast, ...
- LeetCode 141. Linked List Cycle (链表循环)
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...
- 141 Linked List Cycle(判断链表是否有环Medium)
题目意思:链表有环,返回true,否则返回false 思路:两个指针,一快一慢,能相遇则有环,为空了没环 ps:很多链表的题目:都可以采用这种思路 /** * Definition for singl ...
- LeetCode 141. Linked List Cycle(判断链表是否有环)
题意:判断链表是否有环. 分析:快慢指针. /** * Definition for singly-linked list. * struct ListNode { * int val; * List ...
随机推荐
- locate和grep命令
这任然是一篇读书笔记,以下内容来源<linux命令速查手册>这本书. 1.locate命令 用文件名或者文件名的部分来搜索文件在系统中的位置.locate不搜索具体目录,而是搜索一个数据库 ...
- iOS中区分照片的来源
原理就是通过枚举出每个assets group,然后取得group property,group property是个整数,对应头文件中的一些枚举值.用这个可以判断照片是从哪来的(相机胶卷.照片流.相 ...
- HDU 2746 Cyclic Nacklace
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 在织梦dedecms中实现“文章标题-栏目名称-网站名”导航
本文介绍了在dedecms中,实现文章标题-栏目名称-网站名 导航的方法,有需要的朋友参考下. 在dedecms中实现“文章标题-栏目名称-网站名”导航的方法. 第一种: 在/include/in ...
- ES6 解构赋值的常见用途,很强大
字符串 var [a,b,c,d,e] = "hello"; console.log(a); // h console.log(b); // e console.log(c); / ...
- Silverlight DataBinding Converter:根据binding对象调整显示
Silverlight DataBinding Converter:根据binding对象调整显示 我希望写一系列关于Silverlight DataBinding的文章,分别讲解Silverligh ...
- hdu2552
点击打开链接 思路: 1.tan(a+b) = ( tan(a) + tan(b) ) / (1 – tan(a) * tan(b) ) 2.tan( atan(x) ) = x arctan(1/s ...
- python(二):使用multiprocessing中的常见问题
简介在python的解释器中,CPython是应用范围最广的一种,其具有丰富的扩展包,方便了开发者的使用.当然CPython也不是完美的,由于全局解释锁(GIL)的存在,python的多线程可以近似看 ...
- [laravel]请求处理
请求进入 public/index.php 文件. bootstrap/start.php 文件创建应用程序对象并检测环境. 内部的 framework/start.php 文件配置相关设置并加载服务 ...
- 【旧文章搬运】ZwQuerySystemInformation枚举内核模块及简单应用
原文发表于百度空间,2008-10-24========================================================================== 简单说,即 ...