Linked List Cycle
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
对链表反序: while(p) { q=p->next; p->next=f; f=p;p=q;}
/**
* 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) {
ListNode *p=head,*q,*f=NULL;
while(p){//对链表反序,如果p......
阅读全文