141. Linked List Cycle

Given a linked list, determine if it has a cycle in it.

Follow up:
Can you solve it without using extra space?

利用快慢指针,如果相遇则证明有环

注意边界条件: 如果只有一个node.

 public class Solution {
public boolean hasCycle(ListNode head) {
if(head==null || head.next==null) return false;
ListNode slower =head,faster = head;
while(faster!=null && faster.next!=null){
if(faster==slower) return true;
faster = faster.next.next;
slower = slower.next;
}
return false;
}
}
 

最新文章

  1. Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  2. Python 爬虫 字符集乱码问题
  3. Sql Server插入数据并返回自增ID,@@IDENTITY,SCOPE_IDENTITY和IDENT_CURRENT的区别
  4. wc
  5. Windows 提高效率的常用快捷键
  6. 《C与指针》第四章练习
  7. [USACO2004][poj2373]Dividing the Path(DP+单调队列)
  8. AngularJs中的服务
  9. Drupal8开发教程:模块开发——创建新页面
  10. [Codeforces] 347B - Fixed Points
  11. C#线程总结
  12. java 小结1(static ,final,泛型)
  13. python -i filename
  14. c#中传递参数前加out
  15. 另一种数据库连接字符串的编写方式(Sqlbuilder)
  16. db_link
  17. 如何应对苹果app 的ipv6 时代?腾讯专家教您进行环境改造
  18. 自学Python5.1-模块简介
  19. 强化学习(十一) Prioritized Replay DQN
  20. css文字超出一行用点表示

热门文章

  1. com.thoughtworks.xstream.converters.ConversionException
  2. Linux alias 命令
  3. IDEA Intellij 打开springboot项目 配置文件无法出现输入提示
  4. JavaScript的记忆函数真的可以提升性能吗?
  5. poj_3283 trie树
  6. Mybatis——SQL语句构建器类
  7. WEB安全第四篇--与数据库的亲密接触:SQL注入攻击
  8. Eclipse 真机调试检测不到手机解决方案
  9. jhipser微服务架构介绍
  10. PHP unlink()函数,删除文件