标签:模拟 fine turn cti block 技术 hashmap class put
/** * Initialize your data structure here. */ var MyHashMap = function () { this.hashContent = {}; // 使用对象模拟hash表 }; MyHashMap.prototype.put = function (key, value) { this.hashContent[key] = value; // 没有值则赋值 有值则覆盖 }; MyHashMap.prototype.get = function (key) { // 用hasOwnProperty是因为 如果key的val就是undefined 那么用if就无法判断这个key到底存不存在 if (this.hashContent.hasOwnProperty(key)) return this.hashContent[key]; // 也可以用if(key in this.hashContent) // if (key in this.hashContent) return this.hashContent[key]; return -1; }; MyHashMap.prototype.remove = function (key) { if (this.hashContent.hasOwnProperty(key)) delete this.hashContent[key]; };
标签:模拟 fine turn cti block 技术 hashmap class put
原文地址:https://www.cnblogs.com/lanpang9661/p/12657800.html