Created
July 2, 2019 15:32
-
-
Save manojnaidu619/3bfce548cd0b7bbc8d2f4c44e26288ef to your computer and use it in GitHub Desktop.
Leetcode solution for "Linked List Cycle" problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool hasCycle(ListNode *head) { | |
struct ListNode *p=head, *q=head; | |
if(!head || head->next==NULL){ | |
return false; | |
} | |
while(p!=NULL && p->next!=NULL){ | |
p=p->next->next; | |
q=q->next; | |
if(p==q){ | |
return true; | |
} | |
} | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment