mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 141.cpp
This commit is contained in:
parent
4181bb0828
commit
e866e14b86
14
LeetCode-CN/141.cpp
Normal file
14
LeetCode-CN/141.cpp
Normal 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);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user