Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created July 2, 2019 15:32
Show Gist options
  • Save manojnaidu619/3bfce548cd0b7bbc8d2f4c44e26288ef to your computer and use it in GitHub Desktop.
Save manojnaidu619/3bfce548cd0b7bbc8d2f4c44e26288ef to your computer and use it in GitHub Desktop.
Leetcode solution for "Linked List Cycle" problem
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