forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAC_two_points_n.cpp
More file actions
43 lines (35 loc) · 821 Bytes
/
Copy pathAC_two_points_n.cpp
File metadata and controls
43 lines (35 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_two_points_n.cpp
* Create Date: 2015-01-05 11:11:10
* Descripton: two points.
* one step and two steps
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
// 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 *p1 = head, *p2 = head;
while (1) {
if (p1) p1 = p1->next;
else return false;
if (p2) p2 = p2->next;
else return false;
if (p2) p2 = p2->next;
else return false;
if (p1 == p2)
return true;
}
}
};
int main() {
return 0;
}