题目表述:给定一个链表,判断链表中是否有环
Given a linked list, determine if it has a cycle in it.
实例
bool = 1; pos = 1; 存在环路,环路节点为下标为: 1
bool = 1; pos = 0; 存在环路,环路节点下标为: 0
bool = 0; 不存在环路!
函数代码
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head) {
if (head == NULL)
return