This answer


  • 0
    C
    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     ListNode *next;
     *     ListNode(int x) : val(x), next(NULL) {}
     * };
     */
    class Solution {
    public:
        bool hasCycle(ListNode *head) {
            if(head==NULL) return false;
            ListNode *cur,*cur2;
            cur=cur2=head;
            while(cur->next!=NULL && cur2->next->next!=NULL){
                cur = cur->next;
                cur2 = cur2->next->next;
                if(cur == cur2){
                    return true;
                }
            }
            return false;
        }
    };
    

  • 0
    C

    @chnmagnus The answer is false. why?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.