【easy】141. Linked List Cycle
非常简单的题:判断链表有没有环(用快慢指针)
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
bool hasCycle(ListNode *head) {
if (head == NULL)
return false;
ListNode *fast = head;
ListNode *slow = head;
while (fast->next != NULL){
fast = fast->next->next;
slow = slow->next;
if (fast == NULL)
return false;
if (fast == slow)
return true;
}
return false;
}
};
【easy】141. Linked List Cycle的更多相关文章
- 【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】141. Linked List Cycle 解题报告(Java & Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 保存已经走过的路径 日期 [LeetCode ...
- 【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】142. Linked List Cycle II
Difficulty:medium More:[目录]LeetCode Java实现 Description Given a linked list, return the node where t ...
- 【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
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【leetcode❤python】141. Linked List Cycle
#-*- coding: UTF-8 -*- #Method:快慢指针法,建立虚表头,快指针走两步,慢指针走一步,若存在环,则快指针会追上慢指针# Definition for singly-link ...
- 【Lintcode】103.Linked List Cycle II
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. ...
- 【Lintcode】102.Linked List Cycle
题目: Given a linked list, determine if it has a cycle in it. Example Given -21->10->4->5, ta ...
随机推荐
- 一、commander
#!/usr/bin/env node const program = require('commander'); const colors = require('colors'); const pk ...
- 360大牛:全面解读PHP面试
让大家了解基本面试流程和面试的核心要求以及意义是什么并理解PHP面试考点主要以基础为核心,说明PHP面试考察范围. 有需要联系:QQ:1844912514
- DAY24、面向对象
一.复习继承1.父类:在类后()中写父类们2.属性查找顺序:自己->()左侧的父类->依次往右类推3.抽离:先定义子类,由子类的共性抽离出父类 派生:父类已经创建,通过父类再去派生子类4. ...
- python高级编程笔记一 正则表达式
事例
- react 事件绑定 es5/es6
// vscode shift + ctrl + v 预览 es 5 写法 无参函数的绑定 first methods 定义函数: handleClick(e) { // e - 事件对象 e.pre ...
- 代理与hook
参考:Java 动态代理 代理是什么 为什么需要代理呢?其实这个代理与日常生活中的“代理”,“中介”差不多:比如你想海淘买东西,总不可能亲自飞到国外去购物吧,这时候我们使用第三方海淘服务比如惠惠购物助 ...
- ORACLE数据闪回
ALTER TABLE SPM_CON_PAYMENT_RECEIPT ENABLE ROW MOVEMENT; -- 表名 FLASHBACK TABLE SPM_CON_PAYMENT_REC ...
- ubuntu下面配置apache
1.在这个目录下面修改这个文件 把那个注释了 2.在这个目录下面修改这个文件 把这个改为index的目录
- 数据分析三剑客之Matplotlib
Matplotlib绘图和可视化 简介 我的前面两篇文章介绍了 Nimpy ,Pandas .今天来介绍一下Matplotlib. 简单来说,Matplotlib 是 Python 的一个绘图库.它包 ...
- Mergeable Stack ZOJ - 4016(list)
ZOJ - 4016 vector又T又M list是以链表的方式存储的 是一个双向链表 元素转移操作中,不能一个个遍历加入到s中,list独有的splic函数可以在常数时间内实现合并(并删除源lis ...