Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param {number} capacity
- */
- var LFUCache = function(capacity) {
- // capacity is relative to size of LFUCache
- this.capacity = capacity;
- this.storage = {};
- // create counter variable for each insertion
- // each time there is same insertion, increase counter
- // when capacity is full, search for block with lowest counter and remove
- };
- /**
- * @param {number} key
- * @return {number}
- */
- LFUCache.prototype.get = function(key) {
- for( let i = 0; i < this.capacity; i++ ) {
- if( key === this.storage[i][0] ) {
- return this.storage[0][1]
- } else {
- return -1
- }
- }
- };
- /**
- * @param {number} key
- * @param {number} value
- * @return {void}
- */
- LFUCache.prototype.put = function(key, value) {
- var counter = counter || 0;
- // check capacity is not full
- // if capacity is full,
- // look for lowest counter and delete
- this.storage[counter++] = [key, value]
- };
- /**
- * Your LFUCache object will be instantiated and called as such:
- * var obj = Object.create(LFUCache).createNew(capacity)
- * var param_1 = obj.get(key)
- * obj.put(key,value)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement