标签:returns === border isp class lin 性能 pad false
// 使用数组做hash /** * Initialize your data structure here. */ var MyHashSet = function () { this.hashContent = []; }; /** * @param {number} key * @return {void} */ MyHashSet.prototype.add = function (key) { const data = this.hashContent; for (let i = 0; i < data.length; i++) { if (data[i] === key) return null; } data[data.length] = key; }; /** * @param {number} key * @return {void} */ MyHashSet.prototype.remove = function (key) { const data = this.hashContent; for (let i = 0; i < data.length; i++) { if (data[i] === key) data.splice(i, 1); } }; /** * Returns true if this set contains the specified element * @param {number} key * @return {boolean} */ MyHashSet.prototype.contains = function (key) { const data = this.hashContent; for (let i = 0; i < data.length; i++) { if (data[i] === key) return true; } return false; }; /** * Your MyHashSet object will be instantiated and called as such: * var obj = new MyHashSet() * obj.add(key) * obj.remove(key) * var param_3 = obj.contains(key) */
/** * Initialize your data structure here. */ var MyHashSet = function () { this.hashContent = {}; }; /** * @param {number} key * @return {void} */ MyHashSet.prototype.add = function (key) { this.hashContent[key] = true; }; /** * @param {number} key * @return {void} */ MyHashSet.prototype.remove = function (key) { this.hashContent[key] && delete this.hashContent[key]; }; /** * Returns true if this set contains the specified element * @param {number} key * @return {boolean} */ MyHashSet.prototype.contains = function (key) { if (this.hashContent[key]) return true; return false; }; /** * Your MyHashSet object will be instantiated and called as such: * var obj = new MyHashSet() * obj.add(key) * obj.remove(key) * var param_3 = obj.contains(key) */
标签:returns === border isp class lin 性能 pad false
原文地址:https://www.cnblogs.com/lanpang9661/p/12651371.html