Javascript solution


  • 0
    var hasCycle = function(head) {
        if(!head) {
            return false;
        }
        let hash = {};
        while(head) {
            if (hash[head.val]) {
                for(let i = 0; i < hash[head.val].length; i++) {
                    if (head === hash[head.val][i]) {
                        return true;
                    }
                }
                hash[head.val].push(head);
            } else {
                hash[head.val] = [head];
            }
            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.