力扣:141环形链表

class Solution {
public:
    bool hasCycle(ListNode *head) {
        ListNode* fastnode;
        ListNode* slownode;
        if(head){
            fastnode = head;
             slownode = head;
    } else return false;
        while(fastnode->next != NULL && fastnode->next->next){
            fastnode = fastnode->next->next;
            slownode = slownode->next;
            if(fastnode == slownode) return true;        
        }
        return false;
    }
};

版权声明:本文为qq_56762247原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。