直接遍历这个链表,每一次遍历都判断数据是否小于100000,如果小于就让这个数据等于100005,否则就返回true
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
/**
*
* @param head ListNode类
* @return bool布尔型
*/
bool hasCycle(struct ListNode* head ) {
// write code here
struct ListNode *ans;
ans=head;
while(head){
if(head->val!=100005)
head->val=100005;
else return true;
head=head->next;
}
return false;
}