diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/4.460-LFU \347\274\223\345\255\230/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/4.460-LFU \347\274\223\345\255\230/solution.md" index 8477e359e4149ff8b982624cbb121a4d40ef3e94..602e74b0095ccc75587d69302795d4404bdad098 100644 --- "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/4.460-LFU \347\274\223\345\255\230/solution.md" +++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/4.460-LFU \347\274\223\345\255\230/solution.md" @@ -20,57 +20,42 @@
示例:
-输入: +``` ["LFUCache", "put", "put", "get", "put", "get", "get", "put", "get", "get", "get"] - [[2], [1, 1], [2, 2], [1], [3, 3], [2], [3], [4, 4], [1], [3], [4]] +``` 输出: +``` [null, null, null, 1, null, -1, 3, null, -1, 3, 4] +``` 解释: +```java // cnt(x) = 键 x 的使用计数 - // cache=[] 将显示最后一次使用的顺序(最左边的元素是最近的) - LFUCache lFUCache = new LFUCache(2); - lFUCache.put(1, 1); // cache=[1,_], cnt(1)=1 - lFUCache.put(2, 2); // cache=[2,1], cnt(2)=1, cnt(1)=1 - lFUCache.get(1); // 返回 1 - // cache=[1,2], cnt(2)=1, cnt(1)=2 - lFUCache.put(3, 3); // 去除键 2 ,因为 cnt(2)=1 ,使用计数最小 - // cache=[3,1], cnt(3)=1, cnt(1)=2 - lFUCache.get(2); // 返回 -1(未找到) - lFUCache.get(3); // 返回 3 - // cache=[3,1], cnt(3)=2, cnt(1)=2 - lFUCache.put(4, 4); // 去除键 1 ,1 和 3 的 cnt 相同,但 1 最久未使用 - // cache=[4,3], cnt(4)=1, cnt(3)=2 - lFUCache.get(1); // 返回 -1(未找到) - lFUCache.get(3); // 返回 3 - // cache=[3,4], cnt(4)=1, cnt(3)=3 - lFUCache.get(4); // 返回 4 - - // cache=[3,4], cnt(4)=2, cnt(3)=3- + // cache=[3,4], cnt(4)=2, cnt(3)=3 +```
提示:
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/5.146-LRU \347\274\223\345\255\230\346\234\272\345\210\266/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/5.146-LRU \347\274\223\345\255\230\346\234\272\345\210\266/solution.md" index a9eca599130ac2e55de482e402e42c7af433cfdc..e579883f74bc5fc6ceacc40c8f926b8b70843a2c 100644 --- "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/5.146-LRU \347\274\223\345\255\230\346\234\272\345\210\266/solution.md" +++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/5.146-LRU \347\274\223\345\255\230\346\234\272\345\210\266/solution.md" @@ -19,45 +19,36 @@进阶:你是否可以在 O(1)
时间复杂度内完成这两种操作?
示例:
-+ 输入 +``` ["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"] - [[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]] +``` 输出 +``` [null, null, null, 1, null, -1, null, -1, 3, 4] +``` 解释 +```java LRUCache lRUCache = new LRUCache(2); - lRUCache.put(1, 1); // 缓存是 {1=1} - lRUCache.put(2, 2); // 缓存是 {1=1, 2=2} - lRUCache.get(1); // 返回 1 - lRUCache.put(3, 3); // 该操作会使得关键字 2 作废,缓存是 {1=1, 3=3} - lRUCache.get(2); // 返回 -1 (未找到) - lRUCache.put(4, 4); // 该操作会使得关键字 1 作废,缓存是 {4=4, 3=3} - lRUCache.get(1); // 返回 -1 (未找到) - lRUCache.get(3); // 返回 3 - lRUCache.get(4); // 返回 4 - -- - +```
提示:
diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/6.173-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/6.173-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/solution.md" index adf0740a8a5b9be122bab9bedb821b721fd31ca0..aef6e3ce86c9c910d33f050c9ae3a7c4bd9683db 100644 --- "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/6.173-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/solution.md" +++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/6.173-\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/solution.md" @@ -16,42 +16,36 @@你可以假设 next()
调用总是有效的,也就是说,当调用 next()
时,BST 的中序遍历中至少存在一个下一个数字。
示例:
+ 输入 +``` ["BSTIterator", "next", "next", "hasNext", "next", "hasNext", "next", "hasNext", "next", "hasNext"] - [[[7, 3, 15, null, null, 9, 20]], [], [], [], [], [], [], [], [], []] +``` 输出 +``` [null, 3, 7, true, 9, true, 15, true, 20, false] +``` 解释 +```java BSTIterator bSTIterator = new BSTIterator([7, 3, 15, null, null, 9, 20]); - bSTIterator.next(); // 返回 3 - bSTIterator.next(); // 返回 7 - bSTIterator.hasNext(); // 返回 True - bSTIterator.next(); // 返回 9 - bSTIterator.hasNext(); // 返回 True - bSTIterator.next(); // 返回 15 - bSTIterator.hasNext(); // 返回 True - bSTIterator.next(); // 返回 20 - bSTIterator.hasNext(); // 返回 False -+``` diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/7.208-\345\256\236\347\216\260 Trie (\345\211\215\347\274\200\346\240\221)/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/7.208-\345\256\236\347\216\260 Trie (\345\211\215\347\274\200\346\240\221)/solution.md" index d11546e54a52c0c23fafdbea20c051abea90e635..09a7ecf10d8def60032794441643eb2f2cfd2024 100644 --- "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/7.208-\345\256\236\347\216\260 Trie (\345\211\215\347\274\200\346\240\221)/solution.md" +++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/7.208-\345\256\236\347\216\260 Trie (\345\211\215\347\274\200\346\240\221)/solution.md" @@ -22,7 +22,9 @@ 输出 +``` [null, null, true, false, true, null, true] +``` 解释 diff --git "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/9.341-\346\211\201\345\271\263\345\214\226\345\265\214\345\245\227\345\210\227\350\241\250\350\277\255\344\273\243\345\231\250/solution.md" "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/9.341-\346\211\201\345\271\263\345\214\226\345\265\214\345\245\227\345\210\227\350\241\250\350\277\255\344\273\243\345\231\250/solution.md" index 830fd0ca82f9e57df93d3167599a0cb4d2025cdf..9b10671e4d1f5830b27662ddcd8e0b95937bf9d2 100644 --- "a/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/9.341-\346\211\201\345\271\263\345\214\226\345\265\214\345\245\227\345\210\227\350\241\250\350\277\255\344\273\243\345\231\250/solution.md" +++ "b/data/3.\347\256\227\346\263\225\351\253\230\351\230\266/5.leetcode-\350\256\276\350\256\241/9.341-\346\211\201\345\271\263\345\214\226\345\265\214\345\245\227\345\210\227\350\241\250\350\277\255\344\273\243\345\231\250/solution.md" @@ -12,17 +12,13 @@
你的代码将会用下述伪代码检测:
-- +``` initialize iterator with nestedList - res = [] - while iterator.hasNext() - append iterator.next() to the end of res - -return res+return res +```
如果 res
与预期的扁平化列表匹配,那么你的代码将会被判为正确。