[LeetCode]Linked List Cycle
2015-07-26 00:22
453 查看
解题思路:
题目的意思,就好像是在问,一个数组中,有没有重复的数字。因为 如果list中有环,那么必然存在两个指针指向同一个地址。
题目的意思,就好像是在问,一个数组中,有没有重复的数字。因为 如果list中有环,那么必然存在两个指针指向同一个地址。
/** * 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) { set<ListNode*> hashMap; ListNode* cur = head; while(cur != NULL){ if (!hashMap.insert(cur).second){ return true; } cur = cur->next; } return false; } };
相关文章推荐
- wax框架之Lua call oc
- 常见web系统攻击方式归纳
- Codeforces Round #313
- 05-图2. Saving James Bond - Easy Version (25)
- uva 1379(dp)
- 关于jdk的并发集合
- Android触摸机制
- linux下的软件管理器之DPKG
- Nodejs总结
- C语言int类型指针指向char类型变量简单实例
- redis(五)-redis.conf
- 关于指针的++
- GeekBand第二周线下课堂
- JS 父窗口向子窗口传值问题(window.open())
- 又来折腾啦
- 第一百一十四天 how can I 坚持
- ListView的adapter中getView方法一直调用
- Android Framework 记录之一
- 关于Github 的 Watch , Star和Fork
- 一个全新的开始。