You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* * @lc app=leetcode id=981 lang=typescript * * [981] Time Based Key-Value Store */// @lc code=startclassTimeMap{store={}as{[index: string]: [string,number][]}constructor(){}set(key: string,value: string,timestamp: number): void{constval=[value,timestamp]as[string,number];if(!this.store[key]){this.store[key]=[val];}else{this.store[key].push(val);}}get(key: string,timestamp: number): string{letans='';constval=this.store[key];letleft=0;letright=val.length-1;while(left<=right){constmiddle=~~((left+right)/2);if(val[middle][1]<=timestamp){// if current timestamp is greater than the middle element's timestamp// then we can set it to answer becasue we need to return the value// associtated with the largestans=val[middle][0];left=middle+1;}else{right=middle-1;}}returnans;}}/** * Your TimeMap object will be instantiated and called as such: * var obj = new TimeMap() * obj.set(key,value,timestamp) * var param_2 = obj.get(key,timestamp) */// @lc code=end
No description provided.
The text was updated successfully, but these errors were encountered: