题目:

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

Example

Given -21->10->4->5, tail connects to node index 1, return true

题解:

Solution 1 ()

class Solution {
public:
bool hasCycle(ListNode *head) {
if (!head) {
return false;
}
ListNode* fast = head;
ListNode* slow = head;
while (fast && fast->next) {
slow = slow->next;
fast = fast->next->next;
if (slow == fast) {
return true;
}
} return false;
}
};

【Lintcode】102.Linked List Cycle的更多相关文章

  1. 【Lintcode】103.Linked List Cycle II

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

  2. 【LeetCode】142. Linked List Cycle II

    Difficulty:medium  More:[目录]LeetCode Java实现 Description Given a linked list, return the node where t ...

  3. 【LeetCode】141. Linked List Cycle (2 solutions)

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

  4. 【LeetCode】142. Linked List Cycle II (2 solutions)

    Linked List Cycle II Given a linked list, return the node where the cycle begins. If there is no cyc ...

  5. 【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 ...

  6. 【LeetCode】141. Linked List Cycle 解题报告(Java & Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 保存已经走过的路径 日期 [LeetCode ...

  7. 【LeetCode】142. Linked List Cycle II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 set 日期 题目地址:https://le ...

  8. 【easy】141. Linked List Cycle

    非常简单的题:判断链表有没有环(用快慢指针) /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...

  9. 【LeetCode】链表 linked list(共34题)

    [2]Add Two Numbers (2018年11月30日,第一次review,ko) 两个链表,代表两个整数的逆序,返回一个链表,代表两个整数相加和的逆序. Example: Input: ( ...

随机推荐

  1. Java性能小技巧

    局部决定总体. 一个应用的总体性能取决于每一个组件的性能. 以下是一些帮助你提高应用性能的Java编程技巧: 编程技巧 原因及策略 避免反复创建对象 为什么: 更少的对象会须要更少的垃圾回收 使用的空 ...

  2. LeetCode108_Convert SortedArray to BinarySearchTree(将有序数组转成二叉排序树) Java题解

    题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...

  3. VIM中保存编辑的只读文件

    如何在VIM中保存编辑的只读文件 你是否会和我一样经常碰到这样的情景:在VIM中编辑了一个系统配置文件,当需要保存时才发现当前的用户对该文件没有写入的权限.如果已 经做了很多修改,放弃保存的确很懊恼, ...

  4. Jenkins--Run shell command in jenkins as root user?

    You need to modify the permission for jenkins user so that you can run the shell commands. You can i ...

  5. python 基础 8.5 re 的match对象

    #/usr/bin/python #coding=utf-8 #@Time   :2017/11/18 21:49 #@Auther :liuzhenchuan #@File   :match对象.p ...

  6. 函数模板&类模板

    #include <iostream> #if 0//函数模板 template<typename T> T max(T a, T b, T c)//函数模板 { if (a ...

  7. intellij idea使用技巧

    1 小窗口脱离了主窗口的解决办法 只要将floating mode和windowed mode取消掉就可以了,当选择上了floating mode和windowed mode之后会打一个勾,再次点击勾 ...

  8. 阿里云ecs docker使用(4)---mongo docker

    1.新建一个Dockerfile文件  vim Dockerfile #VERSION 0.1.0 FROM ubuntu:14.04 #Install some RUN apt-get clean ...

  9. opencv操作相机相关函数

    1.基本操作 capture = cv2.VideoCapture(0) ret, image = capture.read() cv2.imwrite("photo.jpg", ...

  10. Android 进程增加存活率

    引用 : http://geek.csdn.net/news/detail/68515