Create 141.cpp

master
Kirigaya Kazuto 2018-08-13 22:33:47 +08:00 committed by GitHub
parent 4181bb0828
commit e866e14b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

14
LeetCode-CN/141.cpp Normal file
View File

@ -0,0 +1,14 @@
class Solution {
public:
bool hasCycle(ListNode *head) {
if (head == nullptr || head->next == nullptr) return false;
ListNode* p = head;
ListNode* q = head->next->next;
while (p != q && q && q->next)
{
p = p->next;
q = q->next->next;
}
return (p == q);
}
};