tanchukw

Untitled

Sep 4th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool hasCycle(ListNode *head) {
  4.         ListNode *t1 = head, *t2 = head;
  5.         do
  6.         {
  7.             if (t2 == NULL || t2->next == NULL)
  8.                 return 0;
  9.             t1 = t1->next;
  10.             t2 = t2->next->next;
  11.         } while (t1 != t2);
  12.         return 1;
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment