判断链表是不是循环链表

#include<iostream>
#include<vector>
using namespace std;
/*
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?*/
struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};
class Solution {  //我的思路 错误
public:bool hasCycle(ListNode *head) {ListNode* faster = head;ListNode* slower = head;while (faster->next->next != NULL && faster->next != NULL) {faster = faster->next->next;slower = slower->next;}if (faster==slower)return true;return false;}
};
class Solution {
public:bool hasCycle(ListNode *head) {if (head == NULL)return false;ListNode* faster = head;ListNode* slower = head;while(faster->next->next != NULL && faster->next != NULL) {slower = slower->next;faster = faster->next->next;if (faster == slower)return true;}return false;}
};

Leedcode9-linked-list-cycle-i相关推荐

  1. Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...

  2. LeetCode 142. Linked List Cycle II--单向链表成环的起点--C++,Python解法

    题目地址:Linked List Cycle II - LeetCode Given a linked list, return the node where the cycle begins. If ...

  3. 141. Linked List Cycle

    欢迎fork and star:Nowcoder-Repository-github 141. Linked List Cycle 题目 Given a linked list, determine ...

  4. leetcode: Linked List Cycle II

    http://oj.leetcode.com/problems/linked-list-cycle-ii/ Given a linked list, return the node where the ...

  5. leetcode day5 -- Reorder List Linked List Cycle II

    1.  Reorder List Given a singly linked list L: L0→L1→-→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln ...

  6. LeetCode 之 JavaScript 解答第141题 —— 环形链表 I(Linked List Cycle I)

    Time:2019/4/7 Title: Linked List Cycle Difficulty: Easy Author:小鹿 题目:Linked List Cycle I Given a lin ...

  7. LeetCode141 Linked List Cycle. LeetCode142 Linked List Cycle II

    链表相关题 141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up: Can ...

  8. leetcode - Linked List Cycle

    题目:Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up: Can you solv ...

  9. Leetcode 142 Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...

  10. Leetcode 142. Linked List Cycle II

    地址:Leetcode 142. linked list Cycle II 问题描述:检测链表是否存在环,是的话返回环入口,否则返回None. 这道题有两个思路,一个是经典的快慢指针的思路,另外一个是 ...

最新文章

  1. 24 location对象
  2. python 四边形分割
  3. Matlab的Floor, Ceil, Fix, Round
  4. 地方门户网站运营策略
  5. python与数据库连接的代码_python连接数据库的案例及源代码
  6. table 鼠标移上去改变单元格边框颜色。
  7. 以5个数据库为例,用Python实现数据的提取、转换和加载(ETL)
  8. Ubuntu下安装JDK1.8并配置开发环境
  9. 智能机维修暴利大起底:触摸屏成本30维修300元
  10. Spring 7大功能模块的作用[转]
  11. MYSQL无法连接,提示10055错误尝试解决
  12. dev、test、pre和prod是什么意思?
  13. oracle字段名小写改大写,Oracle数据库中如何实现将将表中字段名转换为大写
  14. 题目内容: 你的程序要读入一系列正整数数据,输入-1表示输入结束,-1本身不是输入的数据。程序输出读到的数据中的奇数和偶数的个数。 输入格式: 一系列正整数,整数的范围是(0,100000)。如果输入
  15. 电阻电容电感二极管三极管在电路中的作用
  16. python网易云爬虫网络技术的意义_Python3爬虫实战之网易云音乐
  17. Web安全——文件上传漏洞
  18. 180701 icon文件查找与转换网站
  19. Syclover战队专访 | 年度终局之战,键指圣诞狂欢
  20. SAP SM30实现表关键字段自增

热门文章

  1. IoT -- (六) MQTT和CoAP对比分析
  2. .某学校的学生公寓有14栋楼,用A~N这14个大写字母的其中一个代表楼号,每栋楼的层数为6层,用1~6六个数字表示。每层楼有40个房间,编号为01~40。具体表示一个宿舍房间时,用1个字母加3位数字表
  3. jenkins重启 linux_在Linux中,Jenkins无法启动
  4. ubuntu php设置,关于ubuntu php环境设置详解-PHP问题
  5. php查到的内容追加到html,javascript - 请问php中如何将查询出来的结果数组转化成自己想要的格式,并在前台利用js输出到html中...
  6. 《常用控制电路》学习笔记——数控锁相环调速电路
  7. matlab m文件的编写,Matlab实验报告(四)M文件的编写.doc
  8. android ble蓝牙接收不到数据_Android蓝牙4.0 Ble读写数据详解 -2
  9. linux下如何为redis配置path,linux环境下如何启动redis
  10. c++ 访问控制与封装