This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const LRUCache = function (capacity) { | |
| this.cache = []; | |
| this.capacity = capacity; | |
| this.count = 0; | |
| }; | |
| LRUCache.prototype.get = function (key) { | |
| const obj = this.cache.find((item) => item.key === key); | |
| if (obj) { | |
| this.cache = this.cache.filter((item) => item.key !== key); | |
| this.cache.push(obj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Heap { | |
| constructor() { | |
| this.container = []; | |
| } | |
| getLeftChildIndex(parentIndex) { | |
| return 2 * parentIndex + 1; | |
| } | |
| getRightChildIndex(parentIndex) { | |
| return 2 * parentIndex + 2; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ROMAN_MAPPING = { | |
| 1: 'I', | |
| 5: 'V', | |
| 10: 'X', | |
| 50: 'L', | |
| 100: 'C', | |
| 500: 'D', | |
| 1000: 'M', | |
| 4: 'IV', | |
| 9: 'IX', |
NewerOlder