【Lintcode】102.Linked List Cycle
题目:
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的更多相关文章
- 【Lintcode】103.Linked List Cycle II
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...
- 【LeetCode】142. Linked List Cycle II
Difficulty:medium More:[目录]LeetCode Java实现 Description Given a linked list, return the node where t ...
- 【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 ...
- 【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 ...
- 【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 ...
- 【LeetCode】141. Linked List Cycle 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 保存已经走过的路径 日期 [LeetCode ...
- 【LeetCode】142. Linked List Cycle II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 set 日期 题目地址:https://le ...
- 【easy】141. Linked List Cycle
非常简单的题:判断链表有没有环(用快慢指针) /** * Definition for singly-linked list. * struct ListNode { * int val; * Lis ...
- 【LeetCode】链表 linked list(共34题)
[2]Add Two Numbers (2018年11月30日,第一次review,ko) 两个链表,代表两个整数的逆序,返回一个链表,代表两个整数相加和的逆序. Example: Input: ( ...
随机推荐
- Ajax请求的跨域(CORS)问题
用浏览器,通过XHR(XMLHttpRequest)请求向另外一个域名请求数据时.会碰到跨域(CORS)问题. CORS:Cross-Origin Resource Sharing 什么是跨域? 简单 ...
- python学习(八)阶段性总结
这里学习了python的一点点基础然后来总结一下 python是一个强类型的语言 数字: 数字的类型大概有:整数.浮点数.复数.固定精度的十进制数.带分子和分母的有理数 数字与字符串之间不能直接相加, ...
- golang中并发sync和channel
golang中实现并发非常简单,只需在需要并发的函数前面添加关键字"go",但是如何处理go并发机制中不同goroutine之间的同步与通信,golang 中提供了sync包和channel ...
- 进程间的八种通信方式----共享内存是最快的 IPC 方式
1.无名管道( pipe ):管道是一种半双工的通信方式,数据只能单向流动,而且只能在具有亲缘关系的进程间使用.进程的亲缘关系通常是指父子进程关系. 2.高级管道(popen):将另一个程序当做一个新 ...
- node.js的http模块的基础 学到的东西
node.js的http模块的基础 学到的东西 其中客户端:我们在node.js中如果要请求服务端中的js或者其他脚本的话要使用http.request()方法他会返回http.ClientReque ...
- jquery 滚动效果插件
1.css <style> .fl { float: left; } .slider0 img { display: block; width:100px; padding: 2px; } ...
- python 基础 7.5 commands 模块
一. commands 模块 1.commands 模块只使用与linxu 的shell 模式下 在我们平时码字时,经常需要调用系统脚本或者系统命令来解决很多问题,接下来,我们就介绍给大家一个很好 ...
- 九度OJ 1069:查找学生信息 (排序、查找)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11240 解决:3024 题目描述: 输入N个学生的信息,然后进行查询. 输入: 输入的第一行为N,即学生的个数(N<=1000) 接 ...
- Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://fromHere.com' is therefore not allowed access.
Failed to load http://wantTOgo.com/get_sts_token/: No 'Access-Control-Allow-Origin' header is presen ...
- 性能测试--siege
siege 这是Linux系统下的一个测试工具,完全使用C语言实现,可以对HTTP和FTP服务器进行负载和性能测试.通过使用Siege 提供的功能,可以很容易的制定测试计划:包括规定使用并发用户数.重 ...