141. Linked List Cycle

来源:互联网 发布:怎么使用bt下载软件 编辑:程序博客网 时间:2024/05/22 13:19
class Solution {public:    bool hasCycle(ListNode *head) {        if(head==NULL||head->next==NULL)            return false;        ListNode* fast=head->next,*slow=head;        while(fast&&slow&&fast->next)        {            if(fast==slow)                return true;            slow=slow->next;            fast=fast->next->next;        }        return false;    }};

0 0
原创粉丝点击