Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- knakul853
- */
- class Solution {
- public:
- bool hasCycle(ListNode *head) { // for removing the node find starting node of the loop and set it's next as null.
- if( !head || !head->next ) return false;
- ListNode* slow = head;
- ListNode* fast = head->next;
- while(slow != fast )
- {
- if( !fast || !fast->next ) return false;
- slow = slow->next;
- fast = fast->next->next;
- }
- return true;
- }
- };
Add Comment
Please, Sign In to add comment