Leetcode77: Linked List Cycle
2015-09-24 11:13
357 查看
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
Follow up:
Can you solve it without using extra space?
/** * 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) { ListNode* fast, *slow; if(!head) return false; fast = head->next; slow = head; while(fast != NULL && fast->next != NULL) { if(fast == slow) return true; fast = fast->next->next; slow = slow->next; } return false; } };
相关文章推荐
- Objective-C中把URL请求的参数转换为字典
- 如何在JavaScript中手动创建类数组对象
- docker常用术语命令
- cygwin
- 不靠谱的Paypal及海外网站
- 在 Windows 上安装 Bugzilla 详解 (1)
- URAL 1080 Map Coloring (BFS)
- Vim自动补全神器:YouCompleteMe
- XML文件写入之DOM解析操作
- Linux 内核配置机制
- 多节点间ssh-无密钥连接配置
- JSP中request解决中文乱码问题(绝对经典)
- java的web project引用java project
- JQery w3school学习第一章 标签的隐藏和显示
- ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- innobackupex命令对mysql数据库进行完全和增量备份
- 栅格_宽度_偏移
- CentOS6.6 配置防火墙
- 移动端技术演进
- Android Studio错误代码不提示问题解决