leetcode No141. Linked List Cycle
来源:互联网 发布:网络机顶盒安装app 编辑:程序博客网 时间:2024/05/24 00:43
Question
Given a linked list, determine if it has a cycle in it.
判断链表是否有环
Algorithm
用两个指针,一快一慢,如果它们会在某一个地方相遇则证明有环
Accepted Code
class Solution {public: bool hasCycle(ListNode *head) { if(head==NULL || head->next==NULL) return false; ListNode *slow=head; ListNode *fast=head; while(fast!=NULL && fast->next!=NULL) { fast=fast->next->next; slow=slow->next; if(slow==fast) return true; } return false; }};
0 0
- leetcode No141. Linked List Cycle
- 【leetcode每日一题】NO141.Linked List Cycle
- leetcode Linked List Cycle & Linked List Cycle ||
- 【LeetCode】Linked List Cycle
- Leetcode: Linked List Cycle
- Leetcode Linked List Cycle
- Leetcode: Linked List Cycle
- LeetCode:Linked List Cycle
- [LeetCode]Linked List Cycle
- LeetCode | Linked List Cycle
- Leetcode: Linked List Cycle
- LeetCode: Linked List Cycle
- LeetCode - Linked List Cycle
- [LeetCode] - Linked List Cycle
- LeetCode - Linked List Cycle
- [LeetCode]Linked List Cycle
- 【LeetCode】Linked List Cycle
- Linked List Cycle - LeetCode
- Hibernate一对一进行数据库的查询
- SpringMVC中的文件上传(大小超限跳转控制)
- 和为S的两个数字 VS 和为S的连续正整数
- swift 方法
- c++常见笔试题(2)
- leetcode No141. Linked List Cycle
- CentOS SSH通信
- 密码学之仿射加密解密算法
- Java基础知识
- spring整合redis教程
- 最近需要整理的任务或者布局
- 程序员技术成长杂谈
- BZOJ 4128 Matrix
- Nginx安装