javaScript solution using buckets and linked list
HashSet internal data structure is based on buckets and linked lists. I think using buckets and linked lists to design hashSet is what interviewers want to see.
HashSet internal data structure is based on buckets and linked lists. I think using buckets and linked lists to design hashSet is what interviewers want to see.\n```\n/**\n * Initialize your data structure here.\n */\nvar LinkedNode = function(value) {\n    this.val = value;\n    this.next = null;\n}\n\nvar MyHashSet = function() {\n    this.buckets = [];\n    this.bucketsLen = 1000;\n};\n\n/** \n * @param {number} key\n * @return {void}\n */\nMyHashSet.prototype.add = function(key) {\n    let hashCode = key % this.bucketsLen;\n    if(!this.buckets[hashCode]) {\n        this.buckets[hashCode] = new LinkedNode(0);\n        let head = this.buckets[hashCode];\n        head.next = new LinkedNode(key);\n        return;\n    } else {\n        let head = this.buckets[hashCode];\n        let point = head;\n        head = head.next;\n        \n        while(head !== null) {\n            if(head.val === key) {\n                return;\n            } else {\n                point = head;\n                head = head.next;\n            }\n                \n        }\n        point.next = new LinkedNode(key);\n        return;\n    }\n};\n\n/** \n * @param {number} key\n * @return {void}\n */\nMyHashSet.prototype.remove = function(key) {\n    let hashCode = key % this.bucketsLen;\n    let head = this.buckets[hashCode];\n    if(!head) {\n        return;\n    } else {\n        let point = head;\n        let cur = head.next;\n        while(cur !== null) {\n            if(cur.val === key) {\n                point.next = cur.next;\n                return;\n            } \n            point = cur;\n            cur = cur.next;\n        }\n    }\n    return;\n};\n\n/**\n * Returns true if this set contains the specified element \n * @param {number} key\n * @return {boolean}\n */\nMyHashSet.prototype.contains = function(key) {\n    let hashCode = key % this.bucketsLen;\n    let head = this.buckets[hashCode];\n    \n    if(!head) {\n        return false;\n    } else {\n        head = head.next;\n        while(head !== null) {\n            if(head.val === key) {\n                return true;\n            }\n            head = head.next;\n        }\n        return false;\n    }\n};\n\n/** \n * Your MyHashSet object will be instantiated and called as such:\n * var obj = new MyHashSet()\n * obj.add(key)\n * obj.remove(key)\n * var param_3 = obj.contains(key)\n */\n ```
[]