02 2022 档案
摘要:// 被观察者类 class Subject { constructor(name) { this.name = name this.observers = [] this.state = 'xx' } // 被观察者提供订阅观察者方法 attach(observer){ this.observer
阅读全文
摘要:// 压缩字符串 'aaaaaabbbbbcccca' => 'a6b5c4a1' function compressStr(strs = 'aaaaaabbbbbccccaa') { let pre = strs[0] let curNum = 1 let res = '' for (let i
阅读全文
摘要:// 新数据插入到链表尾部; // 每当缓存命中(即缓存数据被访问),则将数据移到链表尾部 // 当链表满的时候,将链表头部的数据丢弃。 class LRUCache { constructor(capacity) { this.capacity = capacity this.cache = ne
阅读全文