leetcode-142. 环形链表 II
题目:
代码:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct ListNode{
int val;
ListNode *next;
};
ListNode *detectCycle(ListNode *head) {
vector<ListNode *> v;
ListNode *p;
int flag=0;
while(head){
if(std::find(v.begin(),v.end(),head)!=v.end()){
flag=1;
p=head;
return p;
break;
}else{
v.push_back(head);
}
head=head->next;
}
return NULL;
}
int main(){
ListNode *head,*res;
res=detectCycle(head);
return 0;
}