标签:style class cycle code lin 判断 next tno col
class Solution { public: bool hasCycle(ListNode *head) { if(head == NULL) return false; if(head->next == NULL) return false; ListNode* p1 = head; ListNode* p2 = head; p1 = p1->next; p2 = p2->next->next; while(p2 != NULL && p2->next != NULL && p2->next->next != NULL && p1 != p2){ p1 = p1->next; p2 = p2->next->next; } if(p1 == p2) return true; else return false; } };
141. Linked List Cycle 判断链表是否有环
标签:style class cycle code lin 判断 next tno col
原文地址:http://www.cnblogs.com/ymjyqsx/p/7509719.html