Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
30 lines (28 loc) · 716 Bytes

File metadata and controls

30 lines (28 loc) · 716 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
// Solution142.cpp
// Algorithm
//
// Created by Pancf on 2019/12/21.
// Copyright © 2019 Pancf. All rights reserved.
//
#include "Solution142.hpp"
Solution142::ListNode * Solution142::detectCycle(ListNode *head) {
if (!head) {
return nullptr;
}
auto slow_ptr = head;
auto fast_ptr = head;
while (fast_ptr && fast_ptr->next) {
slow_ptr = slow_ptr->next;
fast_ptr = fast_ptr->next->next;
if (fast_ptr == slow_ptr) {
auto ano_ptr = head;
while (ano_ptr != slow_ptr) {
ano_ptr = ano_ptr->next;
slow_ptr = slow_ptr->next;
}
return ano_ptr;
}
}
return nullptr;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.