1.判断单链表是否存在环
2.找出环节点
node* loopstart(node *head){ if(head==NULL) return NULL; node *fast = head, *slow = head; while(fast && fast->next){ fast = fast->next->next; slow = slow->next; if(fast==slow) break; } if(!fast || !fast->next) return NULL; slow = head; while(fast!=slow){ fast = fast->next; slow = slow->next; } return fast; }
这种方法比较巧,细细体会
1.当判断存在环时,一个从头开始