leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0141.cpp (357B)


0 class Solution { 1 public: 2 bool hasCycle(ListNode *head) { 3 if (!head) return false; 4 5 ListNode *slow, *fast; 6 fast = slow = head; 7 while (fast->next && fast->next->next) { 8 fast = fast->next->next; 9 slow = slow->next; 10 if (fast == slow) return true; 11 } 12 return false; 13 } 14 };