Accepted 9ms, O(0) Space C++ Solution


  • 0
    J

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


Log in to reply
 

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