LeetCode(141)(142) Linked List Cycle I II
来源:互联网 发布:网页页面设计软件 编辑:程序博客网 时间:2024/04/20 23:14
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) { set<ListNode *> visited; ListNode *p1; p1 = head; while(p1 != NULL) { if(visited.count(p1)) return true; else visited.insert(p1); p1 = p1->next; } return false; }};
Linked List Cycle II 代码
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *detectCycle(ListNode *head) { set<ListNode *> visited; ListNode *p1; p1 = head; while(p1 != NULL) { if(visited.count(p1)) return p1; else visited.insert(p1); p1 = p1->next; } return NULL; }};
0 0
- [Leetcode 141 & 142, medium] Linked List Cycle (I and II)
- [leetcode] 141& 142 Linked List Cycle I& II
- leetcode-141-142 Linked List Cycle I II
- leetcode[141&142]:Linked List Cycle I & II
- LeetCode(141)(142) Linked List Cycle I II
- <LeetCode OJ> 141 / 142 Linked List Cycle(I / II)
- [Leetcode] #141#142 Linked List Cycle I & II
- leetcode-141&142 Linked List Cycle I & II
- LeetCode.142(141) Linked List Cycle && Linked List Cycle (II)
- leetcode Linked List Cycle I II
- LeetCode:Linked List Cycle I & II
- LeetCode :: Linked List Cycle I and II
- leetcode Linked List Cycle(I II)(*)
- leetcode-Linked List Cycle I & II
- LeetCode: linked list cycle I and II
- 【LeetCode】Linked List Cycle I&II
- LeetCode - Linked List Cycle I &II
- LeetCode | Linked List Cycle I,II
- LeetCode(20)Valid Parentheses
- GC垃圾收集算法
- Grep用法
- hdu 3593
- C++ class与内存
- LeetCode(141)(142) Linked List Cycle I II
- Linux - 有效群组(effective group)与初始群组(initial group),groups,newgrp
- 高仿SinaWeibo新浪微博发布页面话题效果
- 分享在MVC3.0中使用jQuery DataTable 插件
- FileOutputStream/FileInputStream--FileWriter/FileReader
- 相似图片搜索
- 提示磁盘被写保护怎么办?
- Python中re(正则表达式)模块详解
- 项目开发中用到的一些MySQL语句