leetcode---Linked List Cycle II
2016-10-08 14:33
316 查看
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
Note: Do not modify the linked list.
Note: Do not modify the linked list.
/** * 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*> s; if(head == NULL) return NULL; ListNode *p = head; while(p) { if(s.count(p)) { return p; } s.insert(p); p = p->next; } return NULL; } };
相关文章推荐
- [leetcode] Linked List Cycle II
- leetcode--Linked List Cycle II
- 【LeetCode】-Linked List Cycle II
- 关于Linked List Cycle II (leetcode 142) 的几点思考
- Leetcode Linked List Cycle II
- leetcode-Linked List Cycle II 链表判环以及求环起始位置
- LeetCode题解:Linked List Cycle II
- [LeetCode] Linked List Cycle II
- LeetCode---Linked List Cycle II
- 【leetcode】Linked List Cycle II (middle)
- 【题解】【链表】【Leetcode】Linked List Cycle II
- LeetCode Linked List Cycle II
- 【LeetCode从零单刷】Linked List Cycle I & II
- LeetCode Linked List Cycle II
- [LeetCode#142]Linked List Cycle II
- leetcode — linked-list-cycle-ii
- [leetCode]Linked List Cycle I+II
- LeetCode:Linked List Cycle II
- LeetCode 141 Linked List Cycle和142 Linked List Cycle II
- leetcode Linked List Cycle II python