Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- ListNode *detectCycle(ListNode *head) {
- unordered_set<ListNode*> s;
- while(head!=NULL){
- if(s.find(head)==s.end()){
- s.insert(head);
- }
- else{
- return head;
- }
- head = head->next;
- }
- return NULL;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement