/**
- Definition for singly-linked list.
- struct ListNode {
-
int val; -
ListNode *next; -
ListNode(int x) : val(x), next(NULL) {} - }; */ class Solution { public: bool hasCycle(ListNode *head) { if(head==NULL) return false; ListNode *node=head; int up=10; for(int j=0;j<16;++j){ for(int i=0;i<up;++i){ if(node->next!=NULL){ node=node->next; } else return false; } //check out ListNode test=node; for(int i=0;i<up;++i){ if(node->next!=NULL){ node=node->next; if(node==test) return true; } else return false; } up=2; } return false; } };



京公网安备 11010502036488号