diff --git a/assets/images/705.png b/assets/images/705.png new file mode 100644 index 0000000000..eec7d6effa Binary files /dev/null and b/assets/images/705.png differ diff --git a/assets/scripts/__pycache__/generate.cpython-37.pyc b/assets/scripts/__pycache__/generate.cpython-37.pyc new file mode 100644 index 0000000000..5232a252a4 Binary files /dev/null and b/assets/scripts/__pycache__/generate.cpython-37.pyc differ diff --git a/assets/scripts/create_table.py b/assets/scripts/entrance.py similarity index 100% rename from assets/scripts/create_table.py rename to assets/scripts/entrance.py diff --git a/assets/scripts/generate.py b/assets/scripts/generate.py index 16766070c3..8ad562b77b 100644 --- a/assets/scripts/generate.py +++ b/assets/scripts/generate.py @@ -54,13 +54,13 @@ def format_difficulty(difficulty: str, show_emoji: bool = False): font = "" emoji = "" if difficulty == "困难": - emoji = "🔴" + emoji = "🌶" font = "Hard" elif difficulty == "中等": - emoji = "🟠" + emoji = "🍊" font = "Medium" elif difficulty == "简单": - emoji = "🟢" + emoji = "🍏" font = "Esay" if show_emoji: return emoji + " " + font diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 4fba92fbb0..6981b54090 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -313,6 +313,8 @@ function genLeetCode() { sidebarDepth: 0, children: [ "/leetcode/solution/0700-0799.md", + "/leetcode/problem/0705.md", + "/leetcode/problem/0706.md", "/leetcode/problem/0707.md", "/leetcode/problem/0724.md", "/leetcode/problem/0739.md" diff --git a/docs/leetcode/algorithm/7_sort.md b/docs/leetcode/algorithm/7_sort.md index 4e4d7d9353..f16d8fec41 100644 --- a/docs/leetcode/algorithm/7_sort.md +++ b/docs/leetcode/algorithm/7_sort.md @@ -333,89 +333,91 @@ function swap(arr, i, j) { + ## 相关题目 #### 数组排序 -- 冒泡排序 +* 冒泡排序 + +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 剑指 Offer 45 | [把数组排成最小的数](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | | `贪心` `字符串` `排序` | Medium | +| 0283 | [移动零](https://leetcode.com/problems/move-zeroes/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0283) | `数组` `双指针` | Esay | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :-----------: | :------------------------------------------------------------------------------------------- | :-------------------------------------------------------------: | :--------------------- | :-------------------------------- | -| 剑指 Offer 45 | [把数组排成最小的数](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | | `贪心` `字符串` `排序` | Medium | -| 0283 | [移动零](https://leetcode.com/problems/move-zeroes/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0283) | `数组` `双指针` | Esay | +* 选择排序 -- 选择排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0215 | [数组中的第K个最大元素](https://leetcode.com/problems/kth-largest-element-in-an-array/) | | `数组` `分治` `快速选择` `2+` | Medium | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :---------------------------------------------------------------------------------------- | :--: | :---------------------------- | :-------------------------------- | -| 0215 | [数组中的第 K 个最大元素](https://leetcode.com/problems/kth-largest-element-in-an-array/) | | `数组` `分治` `快速选择` `2+` | Medium | +* 插入排序 -- 插入排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0075 | [颜色分类](https://leetcode.com/problems/sort-colors/) | | `数组` `双指针` `排序` | Medium | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :----------------------------------------------------- | :--: | :--------------------- | :-------------------------------- | -| 0075 | [颜色分类](https://leetcode.com/problems/sort-colors/) | | `数组` `双指针` `排序` | Medium | +* 希尔排序 -- 希尔排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | +| 0506 | [相对名次](https://leetcode.com/problems/relative-ranks/) | | `数组` `排序` `堆(优先队列)` | Esay | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :-------------------------------------------------------- | :--: | :----------------------------- | :-------------------------------- | -| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | -| 0506 | [相对名次](https://leetcode.com/problems/relative-ranks/) | | `数组` `排序` `堆(优先队列)` | Esay | +* 归并排序 -- 归并排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | +| 0088 | [合并两个有序数组](https://leetcode.com/problems/merge-sorted-array/) | | `数组` `双指针` `排序` | Esay | +| 剑指 Offer 51 | [数组中的逆序对](https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | | `树状数组` `线段树` `数组` `4+` | Hard | +| 0315 | [计算右侧小于当前元素的个数](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) | | `树状数组` `线段树` `数组` `4+` | Hard | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :-----------: | :----------------------------------------------------------------------------------------------- | :--: | :------------------------------ | :-------------------------------- | -| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | -| 0088 | [合并两个有序数组](https://leetcode.com/problems/merge-sorted-array/) | | `数组` `双指针` `排序` | Esay | -| 剑指 Offer 51 | [数组中的逆序对](https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | | `树状数组` `线段树` `数组` `4+` | Hard | -| 0315 | [计算右侧小于当前元素的个数](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) | | `树状数组` `线段树` `数组` `4+` | Hard | +* 快速排序 -- 快速排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | +| 0169 | [多数元素](https://leetcode.com/problems/majority-element/) | | `数组` `哈希表` `分治` `2+` | Esay | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :---------------------------------------------------------- | :--: | :-------------------------- | :-------------------------------- | -| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | -| 0169 | [多数元素](https://leetcode.com/problems/majority-element/) | | `数组` `哈希表` `分治` `2+` | Esay | +* 堆排序 -- 堆排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | +| 0215 | [数组中的第K个最大元素](https://leetcode.com/problems/kth-largest-element-in-an-array/) | | `数组` `分治` `快速选择` `2+` | Medium | +| 剑指 Offer 40 | [最小的k个数](https://leetcode.cn/problems/zui-xiao-de-kge-shu-lcof/) | | `数组` `分治` `快速选择` `2+` | Esay | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :-----------: | :---------------------------------------------------------------------------------------- | :--: | :---------------------------- | :-------------------------------- | -| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | -| 0215 | [数组中的第 K 个最大元素](https://leetcode.com/problems/kth-largest-element-in-an-array/) | | `数组` `分治` `快速选择` `2+` | Medium | -| 剑指 Offer 40 | [最小的 k 个数](https://leetcode.cn/problems/zui-xiao-de-kge-shu-lcof/) | | `数组` `分治` `快速选择` `2+` | Esay | +* 计数排序 -- 计数排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | +| 1122 | [数组的相对排序](https://leetcode.com/problems/relative-sort-array/) | | `数组` `哈希表` `计数排序` `1+` | Esay | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :------------------------------------------------------------------- | :--: | :------------------------------ | :-------------------------------- | -| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | -| 1122 | [数组的相对排序](https://leetcode.com/problems/relative-sort-array/) | | `数组` `哈希表` `计数排序` `1+` | Esay | +* 桶排序 -- 桶排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | +| 0220 | [存在重复元素 III](https://leetcode.com/problems/contains-duplicate-iii/) | | `数组` `桶排序` `有序集合` `2+` | Hard | +| 0164 | [最大间距](https://leetcode.com/problems/maximum-gap/) | | `数组` `桶排序` `基数排序` `1+` | Hard | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :------------------------------------------------------------------------ | :--: | :------------------------------ | :-------------------------------- | -| 0912 | [排序数组](https://leetcode.com/problems/sort-an-array/) | | `数组` `分治` `桶排序` `5+` | Medium | -| 0220 | [存在重复元素 III](https://leetcode.com/problems/contains-duplicate-iii/) | | `数组` `桶排序` `有序集合` `2+` | Hard | -| 0164 | [最大间距](https://leetcode.com/problems/maximum-gap/) | | `数组` `桶排序` `基数排序` `1+` | Hard | +* 基数排序 -- 基数排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0164 | [最大间距](https://leetcode.com/problems/maximum-gap/) | | `数组` `桶排序` `基数排序` `1+` | Hard | +| 0561 | [数组拆分](https://leetcode.com/problems/array-partition/) | | `贪心` `数组` `计数排序` `1+` | Esay | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :--------------------------------------------------------- | :--: | :------------------------------ | :------------------------------ | -| 0164 | [最大间距](https://leetcode.com/problems/maximum-gap/) | | `数组` `桶排序` `基数排序` `1+` | Hard | -| 0561 | [数组拆分](https://leetcode.com/problems/array-partition/) | | `贪心` `数组` `计数排序` `1+` | Esay | +* 其他排序 -- 其他排序 +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0217 | [存在重复元素](https://leetcode.com/problems/contains-duplicate/) | | `数组` `哈希表` `排序` | Esay | +| 0136 | [只出现一次的数字](https://leetcode.com/problems/single-number/) | | `位运算` `数组` | Esay | +| 0056 | [合并区间](https://leetcode.com/problems/merge-intervals/) | | `数组` `排序` | Medium | +| 0179 | [最大数](https://leetcode.com/problems/largest-number/) | | `贪心` `数组` `字符串` `1+` | Medium | +| 0384 | [打乱数组](https://leetcode.com/problems/shuffle-an-array/) | | `数组` `数学` `随机化` | Medium | +| 剑指 Offer 45 | [把数组排成最小的数](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | | `贪心` `字符串` `排序` | Medium | -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :-----------: | :------------------------------------------------------------------------------------------- | :--: | :-------------------------- | :-------------------------------- | -| 0217 | [存在重复元素](https://leetcode.com/problems/contains-duplicate/) | | `数组` `哈希表` `排序` | Esay | -| 0136 | [只出现一次的数字](https://leetcode.com/problems/single-number/) | | `位运算` `数组` | Esay | -| 0056 | [合并区间](https://leetcode.com/problems/merge-intervals/) | | `数组` `排序` | Medium | -| 0179 | [最大数](https://leetcode.com/problems/largest-number/) | | `贪心` `数组` `字符串` `1+` | Medium | -| 0384 | [打乱数组](https://leetcode.com/problems/shuffle-an-array/) | | `数组` `数学` `随机化` | Medium | -| 剑指 Offer 45 | [把数组排成最小的数](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | | `贪心` `字符串` `排序` | Medium | diff --git a/docs/leetcode/ds/2_stack.md b/docs/leetcode/ds/2_stack.md index 5c5c6ae156..e5b397661e 100644 --- a/docs/leetcode/ds/2_stack.md +++ b/docs/leetcode/ds/2_stack.md @@ -367,9 +367,9 @@ function add(x, y) { 最终栈中元素为 `[2, 4, 6]`。 ---- +## 单调栈的应用 -### 单调栈的应用 +### 1. 下一个更大元素 ::: tip [496. 下一个更大元素 I - LeetCode](https://2xiao.github.io/leetcode-js/leetcode/problem/0496.html) @@ -436,7 +436,7 @@ var nextGreaterElement = function (nums1, nums2) { ::: ---- +### 2. 每日温度 ::: tip [739. 每日温度 - LeetCode](https://2xiao.github.io/leetcode-js/leetcode/problem/0739.html) @@ -507,35 +507,37 @@ var dailyTemperatures = function (temperatures) { + ## 相关题目 #### 栈基础题目 -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :-----------: | :------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------: | :----------------------- | :-------------------------------- | -| 1047 | [删除字符串中的所有相邻重复项](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1047) | `栈` `字符串` | Esay | -| 0155 | [最小栈](https://leetcode.com/problems/min-stack/) | | `栈` `设计` | Medium | -| 0020 | [有效的括号](https://leetcode.com/problems/valid-parentheses/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0020) | `栈` `字符串` | Esay | -| 0227 | [基本计算器 II](https://leetcode.com/problems/basic-calculator-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0227) | `栈` `数学` `字符串` | Medium | -| 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | `栈` `数组` `单调栈` | Medium | -| 0150 | [逆波兰表达式求值](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | | `栈` `数组` `数学` | Medium | -| 0232 | [用栈实现队列](https://leetcode.com/problems/implement-queue-using-stacks/) | | `栈` `设计` `队列` | Esay | -| 剑指 Offer 09 | [用两个栈实现队列](https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | | `栈` `设计` `队列` | Esay | -| 0394 | [字符串解码](https://leetcode.com/problems/decode-string/) | | `栈` `递归` `字符串` | Medium | -| 0032 | [最长有效括号](https://leetcode.com/problems/longest-valid-parentheses/) | | `栈` `字符串` `动态规划` | Hard | -| 0946 | [验证栈序列](https://leetcode.com/problems/validate-stack-sequences/) | | `栈` `数组` `模拟` | Medium | -| 剑指 Offer 06 | [从尾到头打印链表](https://leetcode.cn/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | | `栈` `递归` `链表` `1+` | Esay | -| 0071 | [简化路径](https://leetcode.com/problems/simplify-path/) | | `栈` `字符串` | Medium | +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 1047 | [删除字符串中的所有相邻重复项](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1047) | `栈` `字符串` | Esay | +| 0155 | [最小栈](https://leetcode.com/problems/min-stack/) | | `栈` `设计` | Medium | +| 0020 | [有效的括号](https://leetcode.com/problems/valid-parentheses/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0020) | `栈` `字符串` | Esay | +| 0227 | [基本计算器 II](https://leetcode.com/problems/basic-calculator-ii/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0227) | `栈` `数学` `字符串` | Medium | +| 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | `栈` `数组` `单调栈` | Medium | +| 0150 | [逆波兰表达式求值](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | | `栈` `数组` `数学` | Medium | +| 0232 | [用栈实现队列](https://leetcode.com/problems/implement-queue-using-stacks/) | | `栈` `设计` `队列` | Esay | +| 剑指 Offer 09 | [用两个栈实现队列](https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | | `栈` `设计` `队列` | Esay | +| 0394 | [字符串解码](https://leetcode.com/problems/decode-string/) | | `栈` `递归` `字符串` | Medium | +| 0032 | [最长有效括号](https://leetcode.com/problems/longest-valid-parentheses/) | | `栈` `字符串` `动态规划` | Hard | +| 0946 | [验证栈序列](https://leetcode.com/problems/validate-stack-sequences/) | | `栈` `数组` `模拟` | Medium | +| 剑指 Offer 06 | [从尾到头打印链表](https://leetcode.cn/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | | `栈` `递归` `链表` `1+` | Esay | +| 0071 | [简化路径](https://leetcode.com/problems/simplify-path/) | | `栈` `字符串` | Medium | #### 单调栈 -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :--: | :---------------------------------------------------------------------------------- | :-------------------------------------------------------------: | :-------------------------- | :-------------------------------- | -| 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | `栈` `数组` `单调栈` | Medium | -| 0496 | [下一个更大元素 I](https://leetcode.com/problems/next-greater-element-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0496) | `栈` `数组` `哈希表` `1+` | Esay | -| 0503 | [下一个更大元素 II](https://leetcode.com/problems/next-greater-element-ii/) | | `栈` `数组` `单调栈` | Medium | -| 0901 | [股票价格跨度](https://leetcode.com/problems/online-stock-span/) | | `栈` `设计` `数据流` `1+` | Medium | -| 0084 | [柱状图中最大的矩形](https://leetcode.com/problems/largest-rectangle-in-histogram/) | | `栈` `数组` `单调栈` | Hard | -| 0316 | [去除重复字母](https://leetcode.com/problems/remove-duplicate-letters/) | | `栈` `贪心` `字符串` `1+` | Medium | -| 0042 | [接雨水](https://leetcode.com/problems/trapping-rain-water/) | | `栈` `数组` `双指针` `2+` | Hard | -| 0085 | [最大矩形](https://leetcode.com/problems/maximal-rectangle/) | | `栈` `数组` `动态规划` `2+` | Hard | +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | `栈` `数组` `单调栈` | Medium | +| 0496 | [下一个更大元素 I](https://leetcode.com/problems/next-greater-element-i/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0496) | `栈` `数组` `哈希表` `1+` | Esay | +| 0503 | [下一个更大元素 II](https://leetcode.com/problems/next-greater-element-ii/) | | `栈` `数组` `单调栈` | Medium | +| 0901 | [股票价格跨度](https://leetcode.com/problems/online-stock-span/) | | `栈` `设计` `数据流` `1+` | Medium | +| 0084 | [柱状图中最大的矩形](https://leetcode.com/problems/largest-rectangle-in-histogram/) | | `栈` `数组` `单调栈` | Hard | +| 0316 | [去除重复字母](https://leetcode.com/problems/remove-duplicate-letters/) | | `栈` `贪心` `字符串` `1+` | Medium | +| 0042 | [接雨水](https://leetcode.com/problems/trapping-rain-water/) | | `栈` `数组` `双指针` `2+` | Hard | +| 0085 | [最大矩形](https://leetcode.com/problems/maximal-rectangle/) | | `栈` `数组` `动态规划` `2+` | Hard | + diff --git a/docs/leetcode/ds/4_hash_table.md b/docs/leetcode/ds/4_hash_table.md index b28dd8d8ae..3978d8330f 100644 --- a/docs/leetcode/ds/4_hash_table.md +++ b/docs/leetcode/ds/4_hash_table.md @@ -1,5 +1,7 @@ # 2.5 哈希表 +## 哈希表的定义 + ::: tip **哈希表(Hash Table)** :也叫做散列表。是根据关键码值(Key Value)直接进行访问的数据结构。 ::: @@ -41,71 +43,1062 @@ 以线性探测为例,往哈希表中插入数据时,如果某个数据经过哈希函数哈希之后,存储位置已经被占用了,就从当前位置开始,依次往后查找,看是否有空闲位置,直到找到为止。 +当发现哈希值 `h` 处产生冲突时,从 `h` 出发,不断地检查 `h+1,h+2,h+3,…` 这些整数对应的位置。 + ### 链表法 -链表法的核心思想是,将具有相同哈希地址的元素存储在同一个线性链表中。 +链表法的核心思想是,为每个哈希值维护一个链表,并将具有相同哈希值的元素都放入这一链表当中。 链表法是一种更加常用的哈希冲突解决方法。相比于开放地址法,链地址法更加简单。 ## 哈希表的实现 -[设计哈希集合](https://leetcode.com/problems/design-hashset/) -[设计哈希映射](https://leetcode.com/problems/design-hashmap/) +### 哈希集合 + +::: tip +[705. 设计哈希集合 - LeetCode](https://2xiao.github.io/leetcode-js/leetcode/problem/0705.html) +::: + +#### ① 题目大意 + +不使用任何内建的哈希表库设计一个哈希集合(HashSet)。 + +实现 `MyHashSet` 类: + +- `void add(key)` 向哈希集合中插入值 `key` 。 +- `bool contains(key)` 返回哈希集合中是否存在这个值 `key` 。 +- `void remove(key)` 将给定值 `key` 从哈希集合中删除。如果哈希集合中没有这个值,什么也不做。 + +**示例**: + +```javascript +MyHashSet myHashSet = new MyHashSet(); +myHashSet.add(1); // set = [1] +myHashSet.add(2); // set = [1, 2] +myHashSet.contains(1); // return True +myHashSet.contains(3); // return False, (not found) +myHashSet.add(2); // set = [1, 2] +myHashSet.contains(2); // return True +myHashSet.remove(2); // set = [1] +myHashSet.contains(2); // return False, (already removed) +``` + +**说明**: + +- `0 <= key <= 10^6`; +- 最多调用 `10^4` 次 `add`、`remove` 和 `contains`; + +#### ② 解题思路 + +链地址法: + +- 设哈希表的大小为 `base`,则可以设计一个简单的哈希函数:`hash(x) = x mod base`; +- 开辟一个大小为 `base` 的数组,数组的每个位置是一个链表。当计算出哈希值之后,就插入到对应位置的链表当中; +- 由于使用整数除法作为哈希函数,为了尽可能避免冲突,应当将 `base` 取为一个质数,如 `base = 769`; + +![](../../../assets/images/705.png) + +- 时间复杂度:`O(n / b)`。其中 `n` 为哈希表中的元素数量,`b` 为链表的数量,假设哈希值是均匀分布的,则每个链表大概长度为 `n / b`; +- 空间复杂度:`O(n+b)`。 + +#### ③ 代码 + +```javascript +class MyHashSet { + constructor() { + this.base = 769 + this.data = new Array(this.base).fill(0).map(() => new Array) + } + + // @param {number} key + // @return {number} + hash (key) { + return key % this.base + } + + // @param {number} key + // @return {void} + add (key) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item === key) return + } + this.data[h].push(key) + } + + // @param {number} key + // @return {void} + remove (key) { + const h = this.hash(key) + const hList = this.data[h] + for (let i = 0; i < hList.length; i++) { + if (hList[i] === key) { + hList.splice(i, 1) + return + } + } + } + + // @param {number} key + // @return {boolean} + contains (key) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item === key) return true + } + return false + } +} + +/** + * Your MyHashSet object will be instantiated and called as such: + * var obj = new MyHashSet() + * obj.add(key) + * obj.remove(key) + * var param_3 = obj.contains(key) + */ +``` + +--- + +### 哈希映射 + +::: tip +[706. 设计哈希映射 - LeetCode](https://2xiao.github.io/leetcode-js/leetcode/problem/0706.html) +::: + +#### ① 题目大意 + +不使用任何内建的哈希表库设计一个哈希映射(HashMap)。 + +实现 `MyHashMap` 类: + +- `MyHashMap()` 用空映射初始化对象 +- `void put(int key, int value)` 向 `HashMap` 插入一个键值对 `(key, value)` 。如果 `key` 已经存在于映射中,则更新其对应的值 `value` 。 +- `int get(int key)` 返回特定的 `key` 所映射的 `value` ;如果映射中不包含 `key` 的映射,返回 `-1` 。 +- `void remove(key)` 如果映射中存在 `key` 的映射,则移除 `key` 和它所对应的 `value` 。 + +**示例**: + +```javascript +MyHashMap myHashMap = new MyHashMap(); +myHashMap.put(1, 1); // The map is now [[1,1]] +myHashMap.put(2, 2); // The map is now [[1,1], [2,2]] +myHashMap.get(1); // return 1, The map is now [[1,1], [2,2]] +myHashMap.get(3); // return -1 (i.e., not found), The map is now [[1,1], [2,2]] +myHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value) +myHashMap.get(2); // return 1, The map is now [[1,1], [2,1]] +myHashMap.remove(2); // remove the mapping for 2, The map is now [[1,1]] +myHashMap.get(2); // return -1 (i.e., not found), The map is now [[1,1]] +``` + +**说明**: + +- `0 <= key, value <= 10^6` +- 最多调用 `10^4` 次 `put`、`get` 和 `remove`; + +#### ② 解题思路 + +链地址法,「设计哈希映射」与「设计哈希集合」解法接近,唯一的区别在于存储的不是 `key` 本身,而是 `(key,value)` 对,其他代码都一样。 + +#### ③ 代码 + +```javascript +class MyHashMap { + constructor () { + this.base = 769 + this.data = new Array(this.base).fill(0).map(() => new Array()) + } + + // @param {number} key + // @return {number} + hash (key) { + return key % this.base + } + + // @param {number} key + // @param {number} value + // @return {void} + put (key, value) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item[0] === key) { + item[1] = value + return + } + } + this.data[h].push([key, value]) + } + + // @param {number} key + // @return {number} + get (key) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item[0] === key) return item[1] + } + return -1 + } + + // @param {number} key + // @return {void} + remove (key) { + const h = this.hash(key) + const hList = this.data[h] + for (let i = 0; i < hList.length; i++) { + if (hList[i][0] === key) { + hList.splice(i, 1) + return + } + } + } +} +/** + * Your MyHashMap object will be instantiated and called as such: + * var obj = new MyHashMap() + * obj.put(key,value) + * var param_2 = obj.get(key) + * obj.remove(key) + */ +``` + +## Set 和 Map +### Set + +#### 基本用法 + +ES6 提供了新的数据结构 Set。它类似于数组,但是成员的值都是唯一的,没有重复的值。 + +`Set`本身是一个构造函数,用来生成 Set 数据结构。 + +```javascript +const s = new Set(); + +[2, 3, 5, 4, 5, 2, 2].forEach(x => s.add(x)); + +for (let i of s) { + console.log(i); +} +// 2 3 5 4 +``` + +上面代码通过`add()`方法向 Set 结构加入成员,结果表明 Set 结构不会添加重复的值。 + +`Set`函数可以接受一个数组(或者具有 iterable 接口的其他数据结构)作为参数,用来初始化。 + +```javascript +// 例一 +const set = new Set([1, 2, 3, 4, 4]); +[...set] +// [1, 2, 3, 4] + +// 例二 +const items = new Set([1, 2, 3, 4, 5, 5, 5, 5]); +items.size // 5 + +// 例三 +const set = new Set(document.querySelectorAll('div')); +set.size // 56 + +// 类似于 +const set = new Set(); +document + .querySelectorAll('div') + .forEach(div => set.add(div)); +set.size // 56 +``` + +上面代码中,例一和例二都是`Set`函数接受数组作为参数,例三是接受类似数组的对象作为参数。 + +上面代码也展示了一种去除数组重复成员的方法。 + +```javascript +// 去除数组的重复成员 +[...new Set(array)] +``` + +上面的方法也可以用于,去除字符串里面的重复字符。 + +```javascript +[...new Set('ababbc')].join('') +// "abc" +``` + +向 Set 加入值的时候,不会发生类型转换,所以`5`和`"5"`是两个不同的值。Set 内部判断两个值是否不同,使用的算法叫做“Same-value-zero equality”,它类似于精确相等运算符(`===`),主要的区别是向 Set 加入值时认为`NaN`等于自身,而精确相等运算符认为`NaN`不等于自身。 + +```javascript +let set = new Set(); +let a = NaN; +let b = NaN; +set.add(a); +set.add(b); +set // Set {NaN} +``` + +上面代码向 Set 实例添加了两次`NaN`,但是只会加入一个。这表明,在 Set 内部,两个`NaN`是相等的。 + +另外,两个对象总是不相等的。 + +```javascript +let set = new Set(); + +set.add({}); +set.size // 1 + +set.add({}); +set.size // 2 +``` + +上面代码表示,由于两个空对象不相等,所以它们被视为两个值。 + +#### Set 实例的属性和方法 + +Set 结构的实例有以下属性。 + +- `Set.prototype.constructor`:构造函数,默认就是`Set`函数。 +- `Set.prototype.size`:返回`Set`实例的成员总数。 + +Set 实例的方法分为两大类:操作方法(用于操作数据)和遍历方法(用于遍历成员)。下面先介绍四个操作方法。 + +- `Set.prototype.add(value)`:添加某个值,返回 Set 结构本身。 +- `Set.prototype.delete(value)`:删除某个值,返回一个布尔值,表示删除是否成功。 +- `Set.prototype.has(value)`:返回一个布尔值,表示该值是否为`Set`的成员。 +- `Set.prototype.clear()`:清除所有成员,没有返回值。 + +上面这些属性和方法的实例如下。 + +```javascript +s.add(1).add(2).add(2); +// 注意2被加入了两次 + +s.size // 2 + +s.has(1) // true +s.has(2) // true +s.has(3) // false + +s.delete(2) // true +s.has(2) // false +``` + +下面是一个对比,判断是否包括一个键,`Object`结构和`Set`结构写法的不同。 + +```javascript +// 对象的写法 +const properties = { + 'width': 1, + 'height': 1 +}; + +if (properties[someName]) { + // do something +} + +// Set的写法 +const properties = new Set(); + +properties.add('width'); +properties.add('height'); + +if (properties.has(someName)) { + // do something +} +``` + +`Array.from()`方法可以将 Set 结构转为数组。 + +```javascript +const items = new Set([1, 2, 3, 4, 5]); +const array = Array.from(items); +``` + +这就提供了去除数组重复成员的另一种方法。 + +```javascript +function dedupe(array) { + return Array.from(new Set(array)); +} + +dedupe([1, 1, 2, 3]) // [1, 2, 3] +``` + +#### 遍历操作 + +Set 结构的实例有四个遍历方法,可以用于遍历成员。 + +- `Set.prototype.keys()`:返回键名的遍历器 +- `Set.prototype.values()`:返回键值的遍历器 +- `Set.prototype.entries()`:返回键值对的遍历器 +- `Set.prototype.forEach()`:使用回调函数遍历每个成员 + +需要特别指出的是,`Set`的遍历顺序就是插入顺序。这个特性有时非常有用,比如使用 Set 保存一个回调函数列表,调用时就能保证按照添加顺序调用。 + +**(1)`keys()`,`values()`,`entries()`** + +`keys`方法、`values`方法、`entries`方法返回的都是遍历器对象(详见《Iterator 对象》一章)。由于 Set 结构没有键名,只有键值(或者说键名和键值是同一个值),所以`keys`方法和`values`方法的行为完全一致。 + +```javascript +let set = new Set(['red', 'green', 'blue']); + +for (let item of set.keys()) { + console.log(item); +} +// red +// green +// blue + +for (let item of set.values()) { + console.log(item); +} +// red +// green +// blue + +for (let item of set.entries()) { + console.log(item); +} +// ["red", "red"] +// ["green", "green"] +// ["blue", "blue"] +``` + +上面代码中,`entries`方法返回的遍历器,同时包括键名和键值,所以每次输出一个数组,它的两个成员完全相等。 + +Set 结构的实例默认可遍历,它的默认遍历器生成函数就是它的`values`方法。 + +```javascript +Set.prototype[Symbol.iterator] === Set.prototype.values +// true +``` + +这意味着,可以省略`values`方法,直接用`for...of`循环遍历 Set。 + +```javascript +let set = new Set(['red', 'green', 'blue']); + +for (let x of set) { + console.log(x); +} +// red +// green +// blue +``` + +**(2)`forEach()`** + +Set 结构的实例与数组一样,也拥有`forEach`方法,用于对每个成员执行某种操作,没有返回值。 + +```javascript +let set = new Set([1, 4, 9]); +set.forEach((value, key) => console.log(key + ' : ' + value)) +// 1 : 1 +// 4 : 4 +// 9 : 9 +``` + +上面代码说明,`forEach`方法的参数就是一个处理函数。该函数的参数与数组的`forEach`一致,依次为键值、键名、集合本身(上例省略了该参数)。这里需要注意,Set 结构的键名就是键值(两者是同一个值),因此第一个参数与第二个参数的值永远都是一样的。 + +另外,`forEach`方法还可以有第二个参数,表示绑定处理函数内部的`this`对象。 + +**(3)遍历的应用** + +扩展运算符(`...`)内部使用`for...of`循环,所以也可以用于 Set 结构。 + +```javascript +let set = new Set(['red', 'green', 'blue']); +let arr = [...set]; +// ['red', 'green', 'blue'] +``` + +扩展运算符和 Set 结构相结合,就可以去除数组的重复成员。 + +```javascript +let arr = [3, 5, 2, 2, 5, 5]; +let unique = [...new Set(arr)]; +// [3, 5, 2] +``` + +而且,数组的`map`和`filter`方法也可以间接用于 Set 了。 + +```javascript +let set = new Set([1, 2, 3]); +set = new Set([...set].map(x => x * 2)); +// 返回Set结构:{2, 4, 6} + +let set = new Set([1, 2, 3, 4, 5]); +set = new Set([...set].filter(x => (x % 2) == 0)); +// 返回Set结构:{2, 4} +``` + +因此使用 Set 可以很容易地实现并集(Union)、交集(Intersect)和差集(Difference)。 + +```javascript +let a = new Set([1, 2, 3]); +let b = new Set([4, 3, 2]); + +// 并集 +let union = new Set([...a, ...b]); +// Set {1, 2, 3, 4} + +// 交集 +let intersect = new Set([...a].filter(x => b.has(x))); +// set {2, 3} + +// (a 相对于 b 的)差集 +let difference = new Set([...a].filter(x => !b.has(x))); +// Set {1} +``` + +如果想在遍历操作中,同步改变原来的 Set 结构,目前没有直接的方法,但有两种变通方法。一种是利用原 Set 结构映射出一个新的结构,然后赋值给原来的 Set 结构;另一种是利用`Array.from`方法。 + +```javascript +// 方法一 +let set = new Set([1, 2, 3]); +set = new Set([...set].map(val => val * 2)); +// set的值是2, 4, 6 + +// 方法二 +let set = new Set([1, 2, 3]); +set = new Set(Array.from(set, val => val * 2)); +// set的值是2, 4, 6 +``` + +上面代码提供了两种方法,直接在遍历操作中改变原来的 Set 结构。 + +### Map -## 哈希表的操作 +#### 含义和基本用法 -数据结构的操作一般涉及到增、删、改、查共 4 种情况,下面我们一起来看一下哈希表的这 4 种基本操作。 +JavaScript 的对象(Object),本质上是键值对的集合(Hash 结构),但是传统上只能用字符串当作键。这给它的使用带来了很大的限制。 -### 1. 增 +```javascript +const data = {}; +const element = document.getElementById('myDiv'); -### 2. 删 +data[element] = 'metadata'; +data['[object HTMLDivElement]'] // "metadata" +``` -### 3. 改 +上面代码原意是将一个 DOM 节点作为对象`data`的键,但是由于对象只接受字符串作为键名,所以`element`被自动转为字符串`[object HTMLDivElement]`。 -### 4. 查 +为了解决这个问题,ES6 提供了 Map 数据结构。它类似于对象,也是键值对的集合,但是“键”的范围不限于字符串,各种类型的值(包括对象)都可以当作键。也就是说,Object 结构提供了“字符串—值”的对应,Map 结构提供了“值—值”的对应,是一种更完善的 Hash 结构实现。如果你需要“键值对”的数据结构,Map 比 Object 更合适。 -## Map +```javascript +const m = new Map(); +const o = {p: 'Hello World'}; + +m.set(o, 'content') +m.get(o) // "content" + +m.has(o) // true +m.delete(o) // true +m.has(o) // false +``` + +上面代码使用 Map 结构的`set`方法,将对象`o`当作`m`的一个键,然后又使用`get`方法读取这个键,接着使用`delete`方法删除了这个键。 + +上面的例子展示了如何向 Map 添加成员。作为构造函数,Map 也可以接受一个数组作为参数。该数组的成员是一个个表示键值对的数组。 + +```javascript +const map = new Map([ + ['name', '张三'], + ['title', 'Author'] +]); + +map.size // 2 +map.has('name') // true +map.get('name') // "张三" +map.has('title') // true +map.get('title') // "Author" +``` + +上面代码在新建 Map 实例时,就指定了两个键`name`和`title`。 + +`Map`构造函数接受数组作为参数,实际上执行的是下面的算法。 + +```javascript +const items = [ + ['name', '张三'], + ['title', 'Author'] +]; + +const map = new Map(); + +items.forEach( + ([key, value]) => map.set(key, value) +); +``` + +事实上,不仅仅是数组,任何具有 Iterator 接口、且每个成员都是一个双元素的数组的数据结构(详见《Iterator》一章)都可以当作`Map`构造函数的参数。这就是说,`Set`和`Map`都可以用来生成新的 Map。 + +```javascript +const set = new Set([ + ['foo', 1], + ['bar', 2] +]); +const m1 = new Map(set); +m1.get('foo') // 1 + +const m2 = new Map([['baz', 3]]); +const m3 = new Map(m2); +m3.get('baz') // 3 +``` + +上面代码中,我们分别使用 Set 对象和 Map 对象,当作`Map`构造函数的参数,结果都生成了新的 Map 对象。 + +如果对同一个键多次赋值,后面的值将覆盖前面的值。 + +```javascript +const map = new Map(); + +map +.set(1, 'aaa') +.set(1, 'bbb'); + +map.get(1) // "bbb" +``` + +上面代码对键`1`连续赋值两次,后一次的值覆盖前一次的值。 + +如果读取一个未知的键,则返回`undefined`。 + +```javascript +new Map().get('asfddfsasadf') +// undefined +``` + +注意,只有对同一个对象的引用,Map 结构才将其视为同一个键。这一点要非常小心。 + +```javascript +const map = new Map(); + +map.set(['a'], 555); +map.get(['a']) // undefined +``` + +上面代码的`set`和`get`方法,表面是针对同一个键,但实际上这是两个不同的数组实例,内存地址是不一样的,因此`get`方法无法读取该键,返回`undefined`。 + +同理,同样的值的两个实例,在 Map 结构中被视为两个键。 + +```javascript +const map = new Map(); + +const k1 = ['a']; +const k2 = ['a']; + +map +.set(k1, 111) +.set(k2, 222); + +map.get(k1) // 111 +map.get(k2) // 222 +``` + +上面代码中,变量`k1`和`k2`的值是一样的,但是它们在 Map 结构中被视为两个键。 + +由上可知,Map 的键实际上是跟内存地址绑定的,只要内存地址不一样,就视为两个键。这就解决了同名属性碰撞(clash)的问题,我们扩展别人的库的时候,如果使用对象作为键名,就不用担心自己的属性与原作者的属性同名。 + +如果 Map 的键是一个简单类型的值(数字、字符串、布尔值),则只要两个值严格相等,Map 将其视为一个键,比如`0`和`-0`就是一个键,布尔值`true`和字符串`true`则是两个不同的键。另外,`undefined`和`null`也是两个不同的键。虽然`NaN`不严格相等于自身,但 Map 将其视为同一个键。 + +```javascript +let map = new Map(); + +map.set(-0, 123); +map.get(+0) // 123 + +map.set(true, 1); +map.set('true', 2); +map.get(true) // 1 + +map.set(undefined, 3); +map.set(null, 4); +map.get(undefined) // 3 + +map.set(NaN, 123); +map.get(NaN) // 123 +``` + +#### 实例的属性和操作方法 + +Map 结构的实例有以下属性和操作方法。 + +**(1)size 属性** + +`size`属性返回 Map 结构的成员总数。 + +```javascript +const map = new Map(); +map.set('foo', true); +map.set('bar', false); + +map.size // 2 +``` + +**(2)Map.prototype.set(key, value)** + +`set`方法设置键名`key`对应的键值为`value`,然后返回整个 Map 结构。如果`key`已经有值,则键值会被更新,否则就新生成该键。 + +```javascript +const m = new Map(); + +m.set('edition', 6) // 键是字符串 +m.set(262, 'standard') // 键是数值 +m.set(undefined, 'nah') // 键是 undefined +``` + +`set`方法返回的是当前的`Map`对象,因此可以采用链式写法。 + +```javascript +let map = new Map() + .set(1, 'a') + .set(2, 'b') + .set(3, 'c'); +``` + +**(3)Map.prototype.get(key)** + +`get`方法读取`key`对应的键值,如果找不到`key`,返回`undefined`。 + +```javascript +const m = new Map(); + +const hello = function() {console.log('hello');}; +m.set(hello, 'Hello ES6!') // 键是函数 + +m.get(hello) // Hello ES6! +``` + +**(4)Map.prototype.has(key)** + +`has`方法返回一个布尔值,表示某个键是否在当前 Map 对象之中。 + +```javascript +const m = new Map(); + +m.set('edition', 6); +m.set(262, 'standard'); +m.set(undefined, 'nah'); + +m.has('edition') // true +m.has('years') // false +m.has(262) // true +m.has(undefined) // true +``` + +**(5)Map.prototype.delete(key)** + +`delete()`方法删除某个键,返回`true`。如果删除失败,返回`false`。 + +```javascript +const m = new Map(); +m.set(undefined, 'nah'); +m.has(undefined) // true + +m.delete(undefined) +m.has(undefined) // false +``` + +**(6)Map.prototype.clear()** + +`clear()`方法清除所有成员,没有返回值。 + +```javascript +let map = new Map(); +map.set('foo', true); +map.set('bar', false); + +map.size // 2 +map.clear() +map.size // 0 +``` + +#### 遍历方法 + +Map 结构原生提供三个遍历器生成函数和一个遍历方法。 + +- `Map.prototype.keys()`:返回键名的遍历器。 +- `Map.prototype.values()`:返回键值的遍历器。 +- `Map.prototype.entries()`:返回所有成员的遍历器。 +- `Map.prototype.forEach()`:遍历 Map 的所有成员。 + +需要特别注意的是,Map 的遍历顺序就是插入顺序。 + +```javascript +const map = new Map([ + ['F', 'no'], + ['T', 'yes'], +]); + +for (let key of map.keys()) { + console.log(key); +} +// "F" +// "T" + +for (let value of map.values()) { + console.log(value); +} +// "no" +// "yes" + +for (let item of map.entries()) { + console.log(item[0], item[1]); +} +// "F" "no" +// "T" "yes" + +// 或者 +for (let [key, value] of map.entries()) { + console.log(key, value); +} +// "F" "no" +// "T" "yes" + +// 等同于使用map.entries() +for (let [key, value] of map) { + console.log(key, value); +} +// "F" "no" +// "T" "yes" +``` + +上面代码最后的那个例子,表示 Map 结构的默认遍历器接口(`Symbol.iterator`属性),就是`entries`方法。 + +```javascript +map[Symbol.iterator] === map.entries +// true +``` + +Map 结构转为数组结构,比较快速的方法是使用扩展运算符(`...`)。 + +```javascript +const map = new Map([ + [1, 'one'], + [2, 'two'], + [3, 'three'], +]); + +[...map.keys()] +// [1, 2, 3] + +[...map.values()] +// ['one', 'two', 'three'] + +[...map.entries()] +// [[1,'one'], [2, 'two'], [3, 'three']] + +[...map] +// [[1,'one'], [2, 'two'], [3, 'three']] +``` + +结合数组的`map`方法、`filter`方法,可以实现 Map 的遍历和过滤(Map 本身没有`map`和`filter`方法)。 + +```javascript +const map0 = new Map() + .set(1, 'a') + .set(2, 'b') + .set(3, 'c'); + +const map1 = new Map( + [...map0].filter(([k, v]) => k < 3) +); +// 产生 Map 结构 {1 => 'a', 2 => 'b'} + +const map2 = new Map( + [...map0].map(([k, v]) => [k * 2, '_' + v]) + ); +// 产生 Map 结构 {2 => '_a', 4 => '_b', 6 => '_c'} +``` + +此外,Map 还有一个`forEach`方法,与数组的`forEach`方法类似,也可以实现遍历。 + +```javascript +map.forEach(function(value, key, map) { + console.log("Key: %s, Value: %s", key, value); +}); +``` + +`forEach`方法还可以接受第二个参数,用来绑定`this`。 + +```javascript +const reporter = { + report: function(key, value) { + console.log("Key: %s, Value: %s", key, value); + } +}; + +map.forEach(function(value, key, map) { + this.report(key, value); +}, reporter); +``` + +上面代码中,`forEach`方法的回调函数的`this`,就指向`reporter`。 + +#### 与其他数据结构的互相转换 + +**(1)Map 转为数组** + +前面已经提过,Map 转为数组最方便的方法,就是使用扩展运算符(`...`)。 + +```javascript +const myMap = new Map() + .set(true, 7) + .set({foo: 3}, ['abc']); +[...myMap] +// [ [ true, 7 ], [ { foo: 3 }, [ 'abc' ] ] ] +``` + +**(2)数组 转为 Map** + +将数组传入 Map 构造函数,就可以转为 Map。 + +```javascript +new Map([ + [true, 7], + [{foo: 3}, ['abc']] +]) +// Map { +// true => 7, +// Object {foo: 3} => ['abc'] +// } +``` + +**(3)Map 转为对象** + +如果所有 Map 的键都是字符串,它可以无损地转为对象。 + +```javascript +function strMapToObj(strMap) { + let obj = Object.create(null); + for (let [k,v] of strMap) { + obj[k] = v; + } + return obj; +} + +const myMap = new Map() + .set('yes', true) + .set('no', false); +strMapToObj(myMap) +// { yes: true, no: false } +``` + +如果有非字符串的键名,那么这个键名会被转成字符串,再作为对象的键名。 + +**(4)对象转为 Map** + +对象转为 Map 可以通过`Object.entries()`。 + +```javascript +let obj = {"a":1, "b":2}; +let map = new Map(Object.entries(obj)); +``` + +此外,也可以自己实现一个转换函数。 + +```javascript +function objToStrMap(obj) { + let strMap = new Map(); + for (let k of Object.keys(obj)) { + strMap.set(k, obj[k]); + } + return strMap; +} + +objToStrMap({yes: true, no: false}) +// Map {"yes" => true, "no" => false} +``` + +**(5)Map 转为 JSON** + +Map 转为 JSON 要区分两种情况。一种情况是,Map 的键名都是字符串,这时可以选择转为对象 JSON。 + +```javascript +function strMapToJson(strMap) { + return JSON.stringify(strMapToObj(strMap)); +} + +let myMap = new Map().set('yes', true).set('no', false); +strMapToJson(myMap) +// '{"yes":true,"no":false}' +``` + +另一种情况是,Map 的键名有非字符串,这时可以选择转为数组 JSON。 + +```javascript +function mapToArrayJson(map) { + return JSON.stringify([...map]); +} + +let myMap = new Map().set(true, 7).set({foo: 3}, ['abc']); +mapToArrayJson(myMap) +// '[[true,7],[{"foo":3},["abc"]]]' +``` + +**(6)JSON 转为 Map** + +JSON 转为 Map,正常情况下,所有键名都是字符串。 + +```javascript +function jsonToStrMap(jsonStr) { + return objToStrMap(JSON.parse(jsonStr)); +} + +jsonToStrMap('{"yes": true, "no": false}') +// Map {'yes' => true, 'no' => false} +``` + +但是,有一种特殊情况,整个 JSON 就是一个数组,且每个数组成员本身,又是一个有两个成员的数组。这时,它可以一一对应地转为 Map。这往往是 Map 转为数组 JSON 的逆操作。 + +```javascript +function jsonToMap(jsonStr) { + return new Map(JSON.parse(jsonStr)); +} + +jsonToMap('[[true,7],[{"foo":3},["abc"]]]') +// Map {true => 7, Object {foo: 3} => ['abc']} +``` -接下来介绍一下 ES6 的 Map 数据结构 -https://zyx.ee/2017/12/20/JavaScript%E5%93%88%E5%B8%8C%E8%A1%A8/ + ## 相关题目 -| 题号 | 标题 | 题解 | 标签 | 难度 | -| :-----------: | :---------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------: | :------------------------------ | :-------------------------------- | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0217 | [存在重复元素](https://leetcode.com/problems/contains-duplicate/) | | `数组` `哈希表` `排序` | Esay | -| 0219 | [存在重复元素 II](https://leetcode.com/problems/contains-duplicate-ii/) | | `数组` `哈希表` `滑动窗口` | Esay | -| 0220 | [存在重复元素 III](https://leetcode.com/problems/contains-duplicate-iii/) | | `数组` `桶排序` `有序集合` `2+` | Hard | -| 1941 | [检查是否所有字符出现次数相同](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | | `哈希表` `字符串` `计数` | Esay | -| 0136 | [只出现一次的数字](https://leetcode.com/problems/single-number/) | | `位运算` `数组` | Esay | -| 0383 | [赎金信](https://leetcode.com/problems/ransom-note/) | | `哈希表` `字符串` `计数` | Esay | -| 0349 | [两个数组的交集](https://leetcode.com/problems/intersection-of-two-arrays/) | | `数组` `哈希表` `双指针` `2+` | Esay | -| 0350 | [两个数组的交集 II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | | `数组` `哈希表` `双指针` `2+` | Esay | -| 0036 | [有效的数独](https://leetcode.com/problems/valid-sudoku/) | | `数组` `哈希表` `矩阵` | Medium | -| 0001 | [两数之和](https://leetcode.com/problems/two-sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0001) | `数组` `哈希表` | Esay | -| 0015 | [三数之和](https://leetcode.com/problems/3sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0015) | `数组` `双指针` `排序` | Medium | -| 0018 | [四数之和](https://leetcode.com/problems/4sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0018) | `数组` `双指针` `排序` | Medium | -| 0454 | [四数相加 II](https://leetcode.com/problems/4sum-ii/) | | `数组` `哈希表` | Medium | -| 0041 | [缺失的第一个正数](https://leetcode.com/problems/first-missing-positive/) | | `数组` `哈希表` | Hard | -| 0128 | [最长连续序列](https://leetcode.com/problems/longest-consecutive-sequence/) | | `并查集` `数组` `哈希表` | Medium | -| 0202 | [快乐数](https://leetcode.com/problems/happy-number/) | | `哈希表` `数学` `双指针` | Esay | -| 0242 | [有效的字母异位词](https://leetcode.com/problems/valid-anagram/) | | `哈希表` `字符串` `排序` | Esay | -| 0205 | [同构字符串](https://leetcode.com/problems/isomorphic-strings/) | | `哈希表` `字符串` | Esay | -| 0442 | [数组中重复的数据](https://leetcode.com/problems/find-all-duplicates-in-an-array/) | | `数组` `哈希表` | Medium | -| 剑指 Offer 61 | [扑克牌中的顺子](https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | | `数组` `排序` | Esay | -| 0268 | [丢失的数字](https://leetcode.com/problems/missing-number/) | | `位运算` `数组` `哈希表` `3+` | Esay | -| 剑指 Offer 03 | [数组中重复的数字](https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | | `数组` `哈希表` `排序` | Esay | -| 0451 | [根据字符出现频率排序](https://leetcode.com/problems/sort-characters-by-frequency/) | | `哈希表` `字符串` `桶排序` `3+` | Medium | -| 0049 | [字母异位词分组](https://leetcode.com/problems/group-anagrams/) | | `数组` `哈希表` `字符串` `1+` | Medium | -| 0599 | [两个列表的最小索引总和](https://leetcode.com/problems/minimum-index-sum-of-two-lists/) | | `数组` `哈希表` `字符串` | Esay | -| 0387 | [字符串中的第一个唯一字符](https://leetcode.com/problems/first-unique-character-in-a-string/) | | `队列` `哈希表` `字符串` `1+` | Esay | -| 0447 | [回旋镖的数量](https://leetcode.com/problems/number-of-boomerangs/) | | `数组` `哈希表` `数学` | Medium | -| 0149 | [直线上最多的点数](https://leetcode.com/problems/max-points-on-a-line/) | | `几何` `数组` `哈希表` `1+` | Hard | -| 0359 | [日志速率限制器](https://leetcode.com/problems/logger-rate-limiter/) | | `设计` `哈希表` | Esay | -| 0811 | [子域名访问计数](https://leetcode.com/problems/subdomain-visit-count/) | | `数组` `哈希表` `字符串` `1+` | Medium | +| 题号 | 标题 | 题解 | 标签 | 难度 | +| :------: | :------ | :------: | :------ | :------ | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | +| 0217 | [存在重复元素](https://leetcode.com/problems/contains-duplicate/) | | `数组` `哈希表` `排序` | Esay | +| 0219 | [存在重复元素 II](https://leetcode.com/problems/contains-duplicate-ii/) | | `数组` `哈希表` `滑动窗口` | Esay | +| 0220 | [存在重复元素 III](https://leetcode.com/problems/contains-duplicate-iii/) | | `数组` `桶排序` `有序集合` `2+` | Hard | +| 1941 | [检查是否所有字符出现次数相同](https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | | `哈希表` `字符串` `计数` | Esay | +| 0136 | [只出现一次的数字](https://leetcode.com/problems/single-number/) | | `位运算` `数组` | Esay | +| 0383 | [赎金信](https://leetcode.com/problems/ransom-note/) | | `哈希表` `字符串` `计数` | Esay | +| 0349 | [两个数组的交集](https://leetcode.com/problems/intersection-of-two-arrays/) | | `数组` `哈希表` `双指针` `2+` | Esay | +| 0350 | [两个数组的交集 II](https://leetcode.com/problems/intersection-of-two-arrays-ii/) | | `数组` `哈希表` `双指针` `2+` | Esay | +| 0036 | [有效的数独](https://leetcode.com/problems/valid-sudoku/) | | `数组` `哈希表` `矩阵` | Medium | +| 0001 | [两数之和](https://leetcode.com/problems/two-sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0001) | `数组` `哈希表` | Esay | +| 0015 | [三数之和](https://leetcode.com/problems/3sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0015) | `数组` `双指针` `排序` | Medium | +| 0018 | [四数之和](https://leetcode.com/problems/4sum/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0018) | `数组` `双指针` `排序` | Medium | +| 0454 | [四数相加 II](https://leetcode.com/problems/4sum-ii/) | | `数组` `哈希表` | Medium | +| 0041 | [缺失的第一个正数](https://leetcode.com/problems/first-missing-positive/) | | `数组` `哈希表` | Hard | +| 0128 | [最长连续序列](https://leetcode.com/problems/longest-consecutive-sequence/) | | `并查集` `数组` `哈希表` | Medium | +| 0202 | [快乐数](https://leetcode.com/problems/happy-number/) | | `哈希表` `数学` `双指针` | Esay | +| 0242 | [有效的字母异位词](https://leetcode.com/problems/valid-anagram/) | | `哈希表` `字符串` `排序` | Esay | +| 0205 | [同构字符串](https://leetcode.com/problems/isomorphic-strings/) | | `哈希表` `字符串` | Esay | +| 0442 | [数组中重复的数据](https://leetcode.com/problems/find-all-duplicates-in-an-array/) | | `数组` `哈希表` | Medium | +| 剑指 Offer 61 | [扑克牌中的顺子](https://leetcode.cn/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | | `数组` `排序` | Esay | +| 0268 | [丢失的数字](https://leetcode.com/problems/missing-number/) | | `位运算` `数组` `哈希表` `3+` | Esay | +| 剑指 Offer 03 | [数组中重复的数字](https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | | `数组` `哈希表` `排序` | Esay | +| 0451 | [根据字符出现频率排序](https://leetcode.com/problems/sort-characters-by-frequency/) | | `哈希表` `字符串` `桶排序` `3+` | Medium | +| 0049 | [字母异位词分组](https://leetcode.com/problems/group-anagrams/) | | `数组` `哈希表` `字符串` `1+` | Medium | +| 0599 | [两个列表的最小索引总和](https://leetcode.com/problems/minimum-index-sum-of-two-lists/) | | `数组` `哈希表` `字符串` | Esay | +| 0387 | [字符串中的第一个唯一字符](https://leetcode.com/problems/first-unique-character-in-a-string/) | | `队列` `哈希表` `字符串` `1+` | Esay | +| 0447 | [回旋镖的数量](https://leetcode.com/problems/number-of-boomerangs/) | | `数组` `哈希表` `数学` | Medium | +| 0149 | [直线上最多的点数](https://leetcode.com/problems/max-points-on-a-line/) | | `几何` `数组` `哈希表` `1+` | Hard | +| 0359 | [日志速率限制器](https://leetcode.com/problems/logger-rate-limiter/) | | `设计` `哈希表` | Esay | +| 0811 | [子域名访问计数](https://leetcode.com/problems/subdomain-visit-count/) | | `数组` `哈希表` `字符串` `1+` | Medium | + diff --git a/docs/leetcode/outline/2_solution_list.md b/docs/leetcode/outline/2_solution_list.md index 426027d8ea..59cf4f67fc 100644 --- a/docs/leetcode/outline/2_solution_list.md +++ b/docs/leetcode/outline/2_solution_list.md @@ -1,6 +1,6 @@ # 1.3 LeetCode 题解 -已完成 81 道 +已完成 83 道 | 题号 | 标题 | 题解 | 标签 | 难度 | | :------: | :------ | :------: | :------ | :------ | @@ -76,6 +76,8 @@ | 0567 | [字符串的排列](https://leetcode.com/problems/permutation-in-string/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0567) | `哈希表` `双指针` `字符串` `1+` | Medium | | 0611 | [有效三角形的个数](https://leetcode.com/problems/valid-triangle-number/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0611) | `贪心` `数组` `双指针` `2+` | Medium | | 0622 | [设计循环队列](https://leetcode.com/problems/design-circular-queue/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0622) | `设计` `队列` `数组` `1+` | Medium | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0707 | [设计链表](https://leetcode.com/problems/design-linked-list/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0707) | `设计` `链表` | Medium | | 0724 | [寻找数组的中心下标](https://leetcode.com/problems/find-pivot-index/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0724) | `数组` `前缀和` | Esay | | 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | `栈` `数组` `单调栈` | Medium | diff --git a/docs/leetcode/outline/3_categories_list.md b/docs/leetcode/outline/3_categories_list.md index dcca53fe74..9a2a7ef305 100644 --- a/docs/leetcode/outline/3_categories_list.md +++ b/docs/leetcode/outline/3_categories_list.md @@ -141,8 +141,8 @@ ::: | 题号 | 标题 | 题解 | 标签 | 难度 | | :------: | :------ | :------: | :------ | :------ | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0217 | [存在重复元素](https://leetcode.com/problems/contains-duplicate/) | | `数组` `哈希表` `排序` | Esay | | 0219 | [存在重复元素 II](https://leetcode.com/problems/contains-duplicate-ii/) | | `数组` `哈希表` `滑动窗口` | Esay | | 0220 | [存在重复元素 III](https://leetcode.com/problems/contains-duplicate-iii/) | | `数组` `桶排序` `有序集合` `2+` | Hard | diff --git a/docs/leetcode/problem/0001.md b/docs/leetcode/problem/0001.md index e8ae432aa0..74d15b651e 100644 --- a/docs/leetcode/problem/0001.md +++ b/docs/leetcode/problem/0001.md @@ -1,6 +1,6 @@ # [1. Two Sum](https://leetcode.com/problems/two-sum/) -🟢 Esay  🔖  [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) ### 题目 diff --git a/docs/leetcode/problem/0002.md b/docs/leetcode/problem/0002.md index 346f6b2581..45a647d98e 100644 --- a/docs/leetcode/problem/0002.md +++ b/docs/leetcode/problem/0002.md @@ -1,6 +1,6 @@ # [2. Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) -🟠 Medium  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) [`数学`](../solution/mathematics.md) +🍊 Medium  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) [`数学`](../solution/mathematics.md) ### 题目 diff --git a/docs/leetcode/problem/0003.md b/docs/leetcode/problem/0003.md index c3c5d5bf52..7848573c70 100644 --- a/docs/leetcode/problem/0003.md +++ b/docs/leetcode/problem/0003.md @@ -1,6 +1,6 @@ # [3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) -🟠 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) +🍊 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) ### 题目 diff --git a/docs/leetcode/problem/0004.md b/docs/leetcode/problem/0004.md index e6323afe31..bfbddd7134 100644 --- a/docs/leetcode/problem/0004.md +++ b/docs/leetcode/problem/0004.md @@ -1,6 +1,6 @@ # [4. Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) -🔴 Hard  🔖  [`数组`](../solution/array.md) [`二分查找`](../solution/binary-search.md) [`分治`](../solution/divide-and-conquer.md) +🌶 Hard  🔖  [`数组`](../solution/array.md) [`二分查找`](../solution/binary-search.md) [`分治`](../solution/divide-and-conquer.md) ### 题目 diff --git a/docs/leetcode/problem/0005.md b/docs/leetcode/problem/0005.md index 3e15ee3425..1654778df9 100644 --- a/docs/leetcode/problem/0005.md +++ b/docs/leetcode/problem/0005.md @@ -1,6 +1,6 @@ # [5. Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) -🟠 Medium  🔖  [`字符串`](../solution/string.md) [`动态规划`](../solution/dynamic-programming.md) +🍊 Medium  🔖  [`字符串`](../solution/string.md) [`动态规划`](../solution/dynamic-programming.md) ### 题目 diff --git a/docs/leetcode/problem/0006.md b/docs/leetcode/problem/0006.md index 1a60eacc16..bdb29b66b4 100644 --- a/docs/leetcode/problem/0006.md +++ b/docs/leetcode/problem/0006.md @@ -1,6 +1,6 @@ # [6. ZigZag Conversion](https://leetcode.com/problems/zigzag-conversion/) -🟠 Medium  🔖  [`字符串`](../solution/string.md) +🍊 Medium  🔖  [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0007.md b/docs/leetcode/problem/0007.md index fcb67ac194..111370a420 100644 --- a/docs/leetcode/problem/0007.md +++ b/docs/leetcode/problem/0007.md @@ -1,6 +1,6 @@ # [7. Reverse Integer](https://leetcode.com/problems/reverse-integer/) -🟠 Medium  🔖  [`数学`](../solution/mathematics.md) +🍊 Medium  🔖  [`数学`](../solution/mathematics.md) ### 题目 diff --git a/docs/leetcode/problem/0008.md b/docs/leetcode/problem/0008.md index e6b9ea0b63..c683d054a0 100644 --- a/docs/leetcode/problem/0008.md +++ b/docs/leetcode/problem/0008.md @@ -1,6 +1,6 @@ # [8. String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/) -🟠 Medium  🔖  [`字符串`](../solution/string.md) +🍊 Medium  🔖  [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0009.md b/docs/leetcode/problem/0009.md index 7d0e1ef5a6..b998a6e885 100644 --- a/docs/leetcode/problem/0009.md +++ b/docs/leetcode/problem/0009.md @@ -1,6 +1,6 @@ # [9. Palindrome Number](https://leetcode.com/problems/palindrome-number/) -🟢 Esay  🔖  [`数学`](../solution/mathematics.md) +🍏 Esay  🔖  [`数学`](../solution/mathematics.md) ### 题目 diff --git a/docs/leetcode/problem/0011.md b/docs/leetcode/problem/0011.md index b260384a96..276d3f0e9e 100644 --- a/docs/leetcode/problem/0011.md +++ b/docs/leetcode/problem/0011.md @@ -1,6 +1,6 @@ # [11. Container With Most Water](https://leetcode.com/problems/container-with-most-water/) -🟠 Medium  🔖  [`贪心`](../solution/greedy.md) [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`贪心`](../solution/greedy.md) [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0013.md b/docs/leetcode/problem/0013.md index 388655a9c3..0bea2ddcff 100644 --- a/docs/leetcode/problem/0013.md +++ b/docs/leetcode/problem/0013.md @@ -1,6 +1,6 @@ # [13. Roman to Integer](https://leetcode.com/problems/roman-to-integer/) -🟢 Esay  🔖  [`哈希表`](../solution/hash-table.md) [`数学`](../solution/mathematics.md) [`字符串`](../solution/string.md) +🍏 Esay  🔖  [`哈希表`](../solution/hash-table.md) [`数学`](../solution/mathematics.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0015.md b/docs/leetcode/problem/0015.md index 6313919f00..9cb7c0de41 100644 --- a/docs/leetcode/problem/0015.md +++ b/docs/leetcode/problem/0015.md @@ -1,6 +1,6 @@ # [15. 3Sum](https://leetcode.com/problems/3sum/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`排序`](../solution/sorting.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`排序`](../solution/sorting.md) ### 题目 diff --git a/docs/leetcode/problem/0016.md b/docs/leetcode/problem/0016.md index 718b827a38..5cdb177722 100644 --- a/docs/leetcode/problem/0016.md +++ b/docs/leetcode/problem/0016.md @@ -1,6 +1,6 @@ # [16. 3Sum Closest](https://leetcode.com/problems/3sum-closest/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`排序`](../solution/sorting.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`排序`](../solution/sorting.md) ### 题目 diff --git a/docs/leetcode/problem/0018.md b/docs/leetcode/problem/0018.md index ead8098abb..855e38c315 100644 --- a/docs/leetcode/problem/0018.md +++ b/docs/leetcode/problem/0018.md @@ -1,6 +1,6 @@ # [18. 4Sum](https://leetcode.com/problems/4sum/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`排序`](../solution/sorting.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`排序`](../solution/sorting.md) ### 题目 diff --git a/docs/leetcode/problem/0019.md b/docs/leetcode/problem/0019.md index 878b01088c..cca5e7adec 100644 --- a/docs/leetcode/problem/0019.md +++ b/docs/leetcode/problem/0019.md @@ -1,6 +1,6 @@ # [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0020.md b/docs/leetcode/problem/0020.md index 69a841a9b8..9182820d45 100644 --- a/docs/leetcode/problem/0020.md +++ b/docs/leetcode/problem/0020.md @@ -1,6 +1,6 @@ # [20. Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/) -🟢 Esay  🔖  [`栈`](../solution/stack.md) [`字符串`](../solution/string.md) +🍏 Esay  🔖  [`栈`](../solution/stack.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0021.md b/docs/leetcode/problem/0021.md index dd86094602..bbb6dd3adb 100644 --- a/docs/leetcode/problem/0021.md +++ b/docs/leetcode/problem/0021.md @@ -1,6 +1,6 @@ # [21. Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) -🟢 Esay  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) +🍏 Esay  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0023.md b/docs/leetcode/problem/0023.md index 01562491f3..8e2abd8cbe 100644 --- a/docs/leetcode/problem/0023.md +++ b/docs/leetcode/problem/0023.md @@ -1,6 +1,6 @@ # [23. Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) -🔴 Hard  🔖  [`链表`](../solution/linked-list.md) [`分治`](../solution/divide-and-conquer.md) [`堆(优先队列)`](../solution/heap-priority-queue.md) [`归并排序`](../solution/merge-sort.md) +🌶 Hard  🔖  [`链表`](../solution/linked-list.md) [`分治`](../solution/divide-and-conquer.md) [`堆(优先队列)`](../solution/heap-priority-queue.md) [`归并排序`](../solution/merge-sort.md) ### 题目 diff --git a/docs/leetcode/problem/0024.md b/docs/leetcode/problem/0024.md index d621c31592..9c0bc67aaa 100644 --- a/docs/leetcode/problem/0024.md +++ b/docs/leetcode/problem/0024.md @@ -1,6 +1,6 @@ # [24. Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/description/) -🟠 Medium  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) +🍊 Medium  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0025.md b/docs/leetcode/problem/0025.md index 3cd093772c..60b1f13f13 100644 --- a/docs/leetcode/problem/0025.md +++ b/docs/leetcode/problem/0025.md @@ -1,7 +1,7 @@ # [25. Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/description/) -🔴 Hard  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) +🌶 Hard  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0026.md b/docs/leetcode/problem/0026.md index 81b887845a..823ef55520 100644 --- a/docs/leetcode/problem/0026.md +++ b/docs/leetcode/problem/0026.md @@ -1,6 +1,6 @@ # [26. Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) -🟢 Esay  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0027.md b/docs/leetcode/problem/0027.md index 496c0d75a8..3a5977fb9a 100644 --- a/docs/leetcode/problem/0027.md +++ b/docs/leetcode/problem/0027.md @@ -1,6 +1,6 @@ # [27. Remove Element](https://leetcode.com/problems/remove-element/) -🟢 Esay  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0033.md b/docs/leetcode/problem/0033.md index cfb7da7e7d..6c1e842cd3 100644 --- a/docs/leetcode/problem/0033.md +++ b/docs/leetcode/problem/0033.md @@ -1,6 +1,6 @@ # [33. Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`二分查找`](../solution/binary-search.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`二分查找`](../solution/binary-search.md) ### 题目 diff --git a/docs/leetcode/problem/0048.md b/docs/leetcode/problem/0048.md index 4d0d6e2bf6..0da44b1a76 100644 --- a/docs/leetcode/problem/0048.md +++ b/docs/leetcode/problem/0048.md @@ -1,6 +1,6 @@ # [48. Rotate Image](https://leetcode.com/problems/rotate-image/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`数学`](../solution/mathematics.md) [`矩阵`](../solution/matrix.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`数学`](../solution/mathematics.md) [`矩阵`](../solution/matrix.md) ### 题目 diff --git a/docs/leetcode/problem/0054.md b/docs/leetcode/problem/0054.md index 2ec3a1ff17..d5c3783d2a 100644 --- a/docs/leetcode/problem/0054.md +++ b/docs/leetcode/problem/0054.md @@ -1,6 +1,6 @@ # [54. Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`矩阵`](../solution/matrix.md) [`模拟`](../solution/simulation.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`矩阵`](../solution/matrix.md) [`模拟`](../solution/simulation.md) ### 题目 diff --git a/docs/leetcode/problem/0059.md b/docs/leetcode/problem/0059.md index e3b3318f33..bd8ceee423 100644 --- a/docs/leetcode/problem/0059.md +++ b/docs/leetcode/problem/0059.md @@ -1,6 +1,6 @@ # [59. Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`矩阵`](../solution/matrix.md) [`模拟`](../solution/simulation.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`矩阵`](../solution/matrix.md) [`模拟`](../solution/simulation.md) ### 题目 diff --git a/docs/leetcode/problem/0061.md b/docs/leetcode/problem/0061.md index 0fe2ea7447..6fe6fc40c4 100644 --- a/docs/leetcode/problem/0061.md +++ b/docs/leetcode/problem/0061.md @@ -1,6 +1,6 @@ # [61. Rotate List](https://leetcode.com/problems/rotate-list/description/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0062.md b/docs/leetcode/problem/0062.md index 877e3585bc..fb3734edf7 100644 --- a/docs/leetcode/problem/0062.md +++ b/docs/leetcode/problem/0062.md @@ -1,6 +1,6 @@ # [62. Unique Paths](https://leetcode.com/problems/unique-paths/) -🟠 Medium  🔖  [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) [`组合数学`](../solution/combinatorics.md) +🍊 Medium  🔖  [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) [`组合数学`](../solution/combinatorics.md) ### 题目 diff --git a/docs/leetcode/problem/0063.md b/docs/leetcode/problem/0063.md index fc6c264f1c..9a5052581a 100644 --- a/docs/leetcode/problem/0063.md +++ b/docs/leetcode/problem/0063.md @@ -1,6 +1,6 @@ # [63. Unique Paths II](https://leetcode.com/problems/unique-paths-ii/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`动态规划`](../solution/dynamic-programming.md) [`矩阵`](../solution/matrix.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`动态规划`](../solution/dynamic-programming.md) [`矩阵`](../solution/matrix.md) ### 题目 diff --git a/docs/leetcode/problem/0066.md b/docs/leetcode/problem/0066.md index dd00bc408b..3033708fad 100644 --- a/docs/leetcode/problem/0066.md +++ b/docs/leetcode/problem/0066.md @@ -1,6 +1,6 @@ # [66. Plus One](https://leetcode.com/problems/plus-one/) -🟢 Esay  🔖  [`数组`](../solution/array.md) [`数学`](../solution/mathematics.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) [`数学`](../solution/mathematics.md) ### 题目 diff --git a/docs/leetcode/problem/0070.md b/docs/leetcode/problem/0070.md index 93db37936c..01b91d9636 100644 --- a/docs/leetcode/problem/0070.md +++ b/docs/leetcode/problem/0070.md @@ -1,7 +1,7 @@ # [70. Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) -🟢 Esay  🔖  [`记忆化搜索`](../solution/memoization.md) [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) +🍏 Esay  🔖  [`记忆化搜索`](../solution/memoization.md) [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) ### 题目 diff --git a/docs/leetcode/problem/0073.md b/docs/leetcode/problem/0073.md index 91c2aff772..e9b717fde9 100644 --- a/docs/leetcode/problem/0073.md +++ b/docs/leetcode/problem/0073.md @@ -1,6 +1,6 @@ # [73. Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) [`矩阵`](../solution/matrix.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) [`矩阵`](../solution/matrix.md) ### 题目 diff --git a/docs/leetcode/problem/0076.md b/docs/leetcode/problem/0076.md index 8458e74358..f9ee4117b0 100644 --- a/docs/leetcode/problem/0076.md +++ b/docs/leetcode/problem/0076.md @@ -1,6 +1,6 @@ # [76. Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) -🔴 Hard  🔖  [`哈希表`](../solution/hash-table.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) +🌶 Hard  🔖  [`哈希表`](../solution/hash-table.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) ### 题目 diff --git a/docs/leetcode/problem/0080.md b/docs/leetcode/problem/0080.md index 841183f291..dc103c2607 100644 --- a/docs/leetcode/problem/0080.md +++ b/docs/leetcode/problem/0080.md @@ -1,6 +1,6 @@ # [80. Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0082.md b/docs/leetcode/problem/0082.md index 38ec2bc110..aaaba5f5ca 100644 --- a/docs/leetcode/problem/0082.md +++ b/docs/leetcode/problem/0082.md @@ -1,6 +1,6 @@ # [82. Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0083.md b/docs/leetcode/problem/0083.md index 62c6558418..6504e64ca6 100644 --- a/docs/leetcode/problem/0083.md +++ b/docs/leetcode/problem/0083.md @@ -1,6 +1,6 @@ # [83. Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) -🟢 Esay  🔖  [`链表`](../solution/linked-list.md) +🍏 Esay  🔖  [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0086.md b/docs/leetcode/problem/0086.md index d24dac677f..5023a08560 100644 --- a/docs/leetcode/problem/0086.md +++ b/docs/leetcode/problem/0086.md @@ -1,6 +1,6 @@ # [86. Partition List](https://leetcode.com/problems/partition-list/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0092.md b/docs/leetcode/problem/0092.md index 0f019392fd..72e3c2a7e5 100644 --- a/docs/leetcode/problem/0092.md +++ b/docs/leetcode/problem/0092.md @@ -1,6 +1,6 @@ # [92. Reverse Linked List II](https://leetcode.com/problems/reverse-linked-list-ii/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0120.md b/docs/leetcode/problem/0120.md index f15e309946..7bffaa8f39 100644 --- a/docs/leetcode/problem/0120.md +++ b/docs/leetcode/problem/0120.md @@ -1,6 +1,6 @@ # [120. Triangle](https://leetcode.com/problems/triangle/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`动态规划`](../solution/dynamic-programming.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`动态规划`](../solution/dynamic-programming.md) ### 题目 diff --git a/docs/leetcode/problem/0125.md b/docs/leetcode/problem/0125.md index 9379887b57..14d6fefa1f 100644 --- a/docs/leetcode/problem/0125.md +++ b/docs/leetcode/problem/0125.md @@ -1,6 +1,6 @@ # [125. Valid Palindrome](https://leetcode.com/problems/valid-palindrome/description/) -🟢 Esay  🔖  [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) +🍏 Esay  🔖  [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0138.md b/docs/leetcode/problem/0138.md index 06c0e82acd..e617cabdf2 100644 --- a/docs/leetcode/problem/0138.md +++ b/docs/leetcode/problem/0138.md @@ -1,6 +1,6 @@ # [138. Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/) -🟠 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) +🍊 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0141.md b/docs/leetcode/problem/0141.md index ff874f1603..96eb128fa6 100644 --- a/docs/leetcode/problem/0141.md +++ b/docs/leetcode/problem/0141.md @@ -1,6 +1,6 @@ # [141. Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/description/) -🟢 Esay  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0142.md b/docs/leetcode/problem/0142.md index bfd277034e..87d15bed20 100644 --- a/docs/leetcode/problem/0142.md +++ b/docs/leetcode/problem/0142.md @@ -1,6 +1,6 @@ # [142. Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) -🟠 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0143.md b/docs/leetcode/problem/0143.md index e929341571..7af38f4ec7 100644 --- a/docs/leetcode/problem/0143.md +++ b/docs/leetcode/problem/0143.md @@ -1,6 +1,6 @@ # [143. Reorder List](https://leetcode.com/problems/reorder-list/) -🟠 Medium  🔖  [`栈`](../solution/stack.md) [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`栈`](../solution/stack.md) [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0146.md b/docs/leetcode/problem/0146.md index 568c228bad..4e79dc8f26 100644 --- a/docs/leetcode/problem/0146.md +++ b/docs/leetcode/problem/0146.md @@ -1,6 +1,6 @@ # [146. LRU Cache](https://leetcode.com/problems/lru-cache/) -🟠 Medium  🔖  [`设计`](../solution/design.md) [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双向链表`](../solution/doubly-linked-list.md) +🍊 Medium  🔖  [`设计`](../solution/design.md) [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双向链表`](../solution/doubly-linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0148.md b/docs/leetcode/problem/0148.md index e9e021c25d..6b2a3b6976 100644 --- a/docs/leetcode/problem/0148.md +++ b/docs/leetcode/problem/0148.md @@ -1,6 +1,6 @@ # [148. Sort List](https://leetcode.com/problems/sort-list/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) [`分治`](../solution/divide-and-conquer.md) [`排序`](../solution/sorting.md) [`归并排序`](../solution/merge-sort.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) [`分治`](../solution/divide-and-conquer.md) [`排序`](../solution/sorting.md) [`归并排序`](../solution/merge-sort.md) ### 题目 diff --git a/docs/leetcode/problem/0152.md b/docs/leetcode/problem/0152.md index f4c4929dde..db8b9a1d86 100644 --- a/docs/leetcode/problem/0152.md +++ b/docs/leetcode/problem/0152.md @@ -1,6 +1,6 @@ # [152. Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`动态规划`](../solution/dynamic-programming.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`动态规划`](../solution/dynamic-programming.md) ### 题目 diff --git a/docs/leetcode/problem/0160.md b/docs/leetcode/problem/0160.md index e4ff32e1fd..145753378d 100644 --- a/docs/leetcode/problem/0160.md +++ b/docs/leetcode/problem/0160.md @@ -1,6 +1,6 @@ # [160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) -🟢 Esay  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0167.md b/docs/leetcode/problem/0167.md index c7b88989e6..bd7f0c1bae 100644 --- a/docs/leetcode/problem/0167.md +++ b/docs/leetcode/problem/0167.md @@ -1,6 +1,6 @@ # [167. Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`二分查找`](../solution/binary-search.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`二分查找`](../solution/binary-search.md) ### 题目 diff --git a/docs/leetcode/problem/0189.md b/docs/leetcode/problem/0189.md index bab76820c6..d832d9e829 100644 --- a/docs/leetcode/problem/0189.md +++ b/docs/leetcode/problem/0189.md @@ -1,6 +1,6 @@ # [189. Rotate Array](https://leetcode.com/problems/rotate-array/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`数学`](../solution/mathematics.md) [`双指针`](../solution/two-pointers.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`数学`](../solution/mathematics.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0190.md b/docs/leetcode/problem/0190.md index 15c5cb89ad..71b21a263d 100644 --- a/docs/leetcode/problem/0190.md +++ b/docs/leetcode/problem/0190.md @@ -1,6 +1,6 @@ # [190. Reverse Bits](https://leetcode.com/problems/reverse-bits/) -🟢 Esay  🔖  [`位运算`](../solution/bit-manipulation.md) [`分治`](../solution/divide-and-conquer.md) +🍏 Esay  🔖  [`位运算`](../solution/bit-manipulation.md) [`分治`](../solution/divide-and-conquer.md) ### 题目 diff --git a/docs/leetcode/problem/0203.md b/docs/leetcode/problem/0203.md index 4736133039..373c289791 100644 --- a/docs/leetcode/problem/0203.md +++ b/docs/leetcode/problem/0203.md @@ -1,6 +1,6 @@ # [203. Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/) -🟢 Esay  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) +🍏 Esay  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0206.md b/docs/leetcode/problem/0206.md index aac4b5eb22..2c258ba1e2 100644 --- a/docs/leetcode/problem/0206.md +++ b/docs/leetcode/problem/0206.md @@ -1,6 +1,6 @@ # [206. Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/description/) -🟢 Esay  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) +🍏 Esay  🔖  [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0224.md b/docs/leetcode/problem/0224.md index 456cf3f233..dc3352a68e 100644 --- a/docs/leetcode/problem/0224.md +++ b/docs/leetcode/problem/0224.md @@ -1,6 +1,6 @@ # [224. Basic Calculator](https://leetcode.com/problems/basic-calculator/) -🔴 Hard  🔖  [`栈`](../solution/stack.md) [`递归`](../solution/recursion.md) [`数学`](../solution/mathematics.md) [`字符串`](../solution/string.md) +🌶 Hard  🔖  [`栈`](../solution/stack.md) [`递归`](../solution/recursion.md) [`数学`](../solution/mathematics.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0227.md b/docs/leetcode/problem/0227.md index 90f5a69cc0..006fe57452 100644 --- a/docs/leetcode/problem/0227.md +++ b/docs/leetcode/problem/0227.md @@ -1,6 +1,6 @@ # [227. Basic Calculator II](https://leetcode.com/problems/basic-calculator-ii/) -🟠 Medium  🔖  [`栈`](../solution/stack.md) [`数学`](../solution/mathematics.md) [`字符串`](../solution/string.md) +🍊 Medium  🔖  [`栈`](../solution/stack.md) [`数学`](../solution/mathematics.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0234.md b/docs/leetcode/problem/0234.md index 49d9b36a62..4f76c32361 100644 --- a/docs/leetcode/problem/0234.md +++ b/docs/leetcode/problem/0234.md @@ -1,6 +1,6 @@ # [234. Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) -🟢 Esay  🔖  [`栈`](../solution/stack.md) [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`栈`](../solution/stack.md) [`递归`](../solution/recursion.md) [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0238.md b/docs/leetcode/problem/0238.md index 5708052ecd..1149d41944 100644 --- a/docs/leetcode/problem/0238.md +++ b/docs/leetcode/problem/0238.md @@ -1,6 +1,6 @@ # [279. Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`前缀和`](../solution/prefix-sum.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`前缀和`](../solution/prefix-sum.md) ### 题目 diff --git a/docs/leetcode/problem/0259.md b/docs/leetcode/problem/0259.md index b1d11517c7..30198884c5 100644 --- a/docs/leetcode/problem/0259.md +++ b/docs/leetcode/problem/0259.md @@ -1,6 +1,6 @@ # [259. 3Sum Smaller](https://leetcode.com/problems/3sum-smaller/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`二分查找`](../solution/binary-search.md) [`排序`](../solution/sorting.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`二分查找`](../solution/binary-search.md) [`排序`](../solution/sorting.md) ### 题目 diff --git a/docs/leetcode/problem/0279.md b/docs/leetcode/problem/0279.md index f9f8db3d81..0d4945deab 100644 --- a/docs/leetcode/problem/0279.md +++ b/docs/leetcode/problem/0279.md @@ -1,6 +1,6 @@ # [279. Perfect Squares](https://leetcode.com/problems/perfect-squares/) -🟠 Medium  🔖  [`广度优先搜索`](../solution/breadth-first-search.md) [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) +🍊 Medium  🔖  [`广度优先搜索`](../solution/breadth-first-search.md) [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) ### 题目 diff --git a/docs/leetcode/problem/0283.md b/docs/leetcode/problem/0283.md index 9b25c55bfc..255a6d3369 100644 --- a/docs/leetcode/problem/0283.md +++ b/docs/leetcode/problem/0283.md @@ -1,6 +1,6 @@ # [283. Move Zeroes](https://leetcode.com/problems/move-zeroes/) -🟢 Esay  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/0328.md b/docs/leetcode/problem/0328.md index 59ce8860d4..c54e60232d 100644 --- a/docs/leetcode/problem/0328.md +++ b/docs/leetcode/problem/0328.md @@ -1,6 +1,6 @@ # [328. Odd Even Linked List](https://leetcode.com/problems/odd-even-linked-list/) -🟠 Medium  🔖  [`链表`](../solution/linked-list.md) +🍊 Medium  🔖  [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0344.md b/docs/leetcode/problem/0344.md index cf3b73f59a..92649a7ca7 100644 --- a/docs/leetcode/problem/0344.md +++ b/docs/leetcode/problem/0344.md @@ -1,6 +1,6 @@ # [344. Reverse String](https://leetcode.com/problems/reverse-string/) -🟢 Esay  🔖  [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) +🍏 Esay  🔖  [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0345.md b/docs/leetcode/problem/0345.md index 8d6df59c49..845953d218 100644 --- a/docs/leetcode/problem/0345.md +++ b/docs/leetcode/problem/0345.md @@ -1,6 +1,6 @@ # [345. Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/) -🟢 Esay  🔖  [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) +🍏 Esay  🔖  [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/0430.md b/docs/leetcode/problem/0430.md index a72e261bce..b1eeacd324 100644 --- a/docs/leetcode/problem/0430.md +++ b/docs/leetcode/problem/0430.md @@ -1,6 +1,6 @@ # [430. Flatten a Multilevel Doubly Linked List](https://leetcode.com/problems/flatten-a-multilevel-doubly-linked-list/) -🟠 Medium  🔖  [`深度优先搜索`](../solution/depth-first-search.md) [`链表`](../solution/linked-list.md) [`双向链表`](../solution/doubly-linked-list.md) +🍊 Medium  🔖  [`深度优先搜索`](../solution/depth-first-search.md) [`链表`](../solution/linked-list.md) [`双向链表`](../solution/doubly-linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0438.md b/docs/leetcode/problem/0438.md index 5627daeb1e..d9d4a7a943 100644 --- a/docs/leetcode/problem/0438.md +++ b/docs/leetcode/problem/0438.md @@ -1,6 +1,6 @@ # [438. Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/) -🟠 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) +🍊 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) ### 题目 diff --git a/docs/leetcode/problem/0485.md b/docs/leetcode/problem/0485.md index 301f552f08..c9d55ba870 100644 --- a/docs/leetcode/problem/0485.md +++ b/docs/leetcode/problem/0485.md @@ -1,6 +1,6 @@ # [485. Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/) -🟢 Esay  🔖  [`数组`](../solution/array.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) ### 题目 diff --git a/docs/leetcode/problem/0496.md b/docs/leetcode/problem/0496.md index 6f748c80b5..e16038690e 100644 --- a/docs/leetcode/problem/0496.md +++ b/docs/leetcode/problem/0496.md @@ -1,6 +1,6 @@ # [496. Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/) -🟢 Esay  🔖  [`栈`](../solution/stack.md) [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) [`单调栈`](../solution/monotonic-stack.md) +🍏 Esay  🔖  [`栈`](../solution/stack.md) [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) [`单调栈`](../solution/monotonic-stack.md) ### 题目 diff --git a/docs/leetcode/problem/0498.md b/docs/leetcode/problem/0498.md index 4c17174e91..c8cb6b5719 100644 --- a/docs/leetcode/problem/0498.md +++ b/docs/leetcode/problem/0498.md @@ -1,6 +1,6 @@ # [498. Diagonal Traverse](https://leetcode.com/problems/diagonal-traverse/) -🟠 Medium  🔖  [`数组`](../solution/array.md) [`矩阵`](../solution/matrix.md) [`模拟`](../solution/simulation.md) +🍊 Medium  🔖  [`数组`](../solution/array.md) [`矩阵`](../solution/matrix.md) [`模拟`](../solution/simulation.md) ### 题目 diff --git a/docs/leetcode/problem/0509.md b/docs/leetcode/problem/0509.md index 3fbe67f503..b26267921e 100644 --- a/docs/leetcode/problem/0509.md +++ b/docs/leetcode/problem/0509.md @@ -1,6 +1,6 @@ # [509. Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) -🟢 Esay  🔖  [`递归`](../solution/recursion.md) [`记忆化搜索`](../solution/memoization.md) [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) +🍏 Esay  🔖  [`递归`](../solution/recursion.md) [`记忆化搜索`](../solution/memoization.md) [`数学`](../solution/mathematics.md) [`动态规划`](../solution/dynamic-programming.md) ### 题目 diff --git a/docs/leetcode/problem/0567.md b/docs/leetcode/problem/0567.md index 352f536d2b..b52585841b 100644 --- a/docs/leetcode/problem/0567.md +++ b/docs/leetcode/problem/0567.md @@ -1,6 +1,6 @@ # [567. Permutation in String](https://leetcode.com/problems/permutation-in-string/) -🟠 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) +🍊 Medium  🔖  [`哈希表`](../solution/hash-table.md) [`双指针`](../solution/two-pointers.md) [`字符串`](../solution/string.md) [`滑动窗口`](../solution/sliding-window.md) ### 题目 diff --git a/docs/leetcode/problem/0611.md b/docs/leetcode/problem/0611.md index 9ae66eb5aa..6dee2a0bc1 100644 --- a/docs/leetcode/problem/0611.md +++ b/docs/leetcode/problem/0611.md @@ -1,6 +1,6 @@ # [611. Valid Triangle Number](https://leetcode.com/problems/valid-triangle-number/) -🟠 Medium  🔖  [`贪心`](../solution/greedy.md) [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`二分查找`](../solution/binary-search.md) [`排序`](../solution/sorting.md) +🍊 Medium  🔖  [`贪心`](../solution/greedy.md) [`数组`](../solution/array.md) [`双指针`](../solution/two-pointers.md) [`二分查找`](../solution/binary-search.md) [`排序`](../solution/sorting.md) ### 题目 diff --git a/docs/leetcode/problem/0622.md b/docs/leetcode/problem/0622.md index 6b97671c2c..4e458af3d4 100644 --- a/docs/leetcode/problem/0622.md +++ b/docs/leetcode/problem/0622.md @@ -1,6 +1,6 @@ # [622. Design Circular Queue](https://leetcode.com/problems/design-circular-queue/) -🟠 Medium  🔖  [`设计`](../solution/design.md) [`队列`](../solution/queue.md) [`数组`](../solution/array.md) [`链表`](../solution/linked-list.md) +🍊 Medium  🔖  [`设计`](../solution/design.md) [`队列`](../solution/queue.md) [`数组`](../solution/array.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0705.md b/docs/leetcode/problem/0705.md new file mode 100755 index 0000000000..21f4e4c3a4 --- /dev/null +++ b/docs/leetcode/problem/0705.md @@ -0,0 +1,113 @@ +# [705. Design HashSet](https://leetcode.com/problems/design-hashset/) + + +🍏 Esay  🔖  [`设计`](../solution/design.md) [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`哈希函数`](../solution/hash-function.md) + +### 题目 + +Design a HashSet without using any built-in hash table libraries. + +Implement `MyHashSet` class: + +- `void add(key)` Inserts the value `key` into the HashSet. +- `bool contains(key)` Returns whether the value `key` exists in the HashSet or not. +- `void remove(key)` Removes the value `key` in the HashSet. If `key` does not exist in the HashSet, do nothing. + +**Example**: +```javascript +MyHashSet myHashSet = new MyHashSet(); +myHashSet.add(1); // set = [1] +myHashSet.add(2); // set = [1, 2] +myHashSet.contains(1); // return True +myHashSet.contains(3); // return False, (not found) +myHashSet.add(2); // set = [1, 2] +myHashSet.contains(2); // return True +myHashSet.remove(2); // set = [1] +myHashSet.contains(2); // return False, (already removed) +``` +**Note**: + +- `0 <= key <= 10^6` +- 最多调用 `10^4` 次 `add`、`remove` 和 `contains` +- Please do not use the built-in HashSet library. + +### 题目大意 + +不使用任何内建的哈希表库设计一个哈希集合(HashSet)。 + +实现 `MyHashSet` 类: + +- `void add(key)` 向哈希集合中插入值 `key` 。 +- `bool contains(key)` 返回哈希集合中是否存在这个值 `key` 。 +- `void remove(key)` 将给定值 `key` 从哈希集合中删除。如果哈希集合中没有这个值,什么也不做。 + +### 解题思路 + +链地址法: + +- 设哈希表的大小为 `base`,则可以设计一个简单的哈希函数:`hash(x) = x mod base`; +- 开辟一个大小为 `base` 的数组,数组的每个位置是一个链表。当计算出哈希值之后,就插入到对应位置的链表当中; +- 由于使用整数除法作为哈希函数,为了尽可能避免冲突,应当将 `base` 取为一个质数,如 `base = 769`; + +![](../../../assets/images/705.png) + +- 时间复杂度:`O(n / b)`。其中 `n` 为哈希表中的元素数量,`b` 为链表的数量,假设哈希值是均匀分布的,则每个链表大概长度为 `n / b`; +- 空间复杂度:`O(n+b)`。 + +### 代码 + +```javascript +class MyHashSet { + constructor() { + this.base = 769 + this.data = new Array(this.base).fill(0).map(() => new Array) + } + + // @param {number} key + // @return {number} + hash (key) { + return key % this.base + } + + // @param {number} key + // @return {void} + add (key) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item === key) return + } + this.data[h].push(key) + } + + // @param {number} key + // @return {void} + remove (key) { + const h = this.hash(key) + const hList = this.data[h] + for (let i = 0; i < hList.length; i++) { + if (hList[i] === key) { + hList.splice(i, 1) + return + } + } + } + + // @param {number} key + // @return {boolean} + contains (key) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item === key) return true + } + return false + } +} + +/** + * Your MyHashSet object will be instantiated and called as such: + * var obj = new MyHashSet() + * obj.add(key) + * obj.remove(key) + * var param_3 = obj.contains(key) + */ +``` diff --git a/docs/leetcode/problem/0706.md b/docs/leetcode/problem/0706.md new file mode 100755 index 0000000000..b2629a5d66 --- /dev/null +++ b/docs/leetcode/problem/0706.md @@ -0,0 +1,123 @@ +# [706. Design HashMap](https://leetcode.com/problems/design-hashmap/) + + +🍏 Esay  🔖  [`设计`](../solution/design.md) [`数组`](../solution/array.md) [`哈希表`](../solution/hash-table.md) [`链表`](../solution/linked-list.md) [`哈希函数`](../solution/hash-function.md) + +### 题目 + +Design a HashMap without using any built-in hash table libraries. + +Implement the `MyHashMap` class: + +- `MyHashMap()` initializes the object with an empty map. +- `void put(int key, int value)` inserts a `(key, value)` pair into the HashMap. If the `key` already exists in the map, update the corresponding `value`. +- `int get(int key)` returns the `value` to which the specified `key` is mapped, or `-1` if this map contains no mapping for the `key`. +- `void remove(key)` removes the `key` and its corresponding `value` if the map contains the mapping for the `key`. + +**Example**: + +```javascript +MyHashMap myHashMap = new MyHashMap(); +myHashMap.put(1, 1); // The map is now [[1,1]] +myHashMap.put(2, 2); // The map is now [[1,1], [2,2]] +myHashMap.get(1); // return 1, The map is now [[1,1], [2,2]] +myHashMap.get(3); // return -1 (i.e., not found), The map is now [[1,1], [2,2]] +myHashMap.put(2, 1); // The map is now [[1,1], [2,1]] (i.e., update the existing value) +myHashMap.get(2); // return 1, The map is now [[1,1], [2,1]] +myHashMap.remove(2); // remove the mapping for 2, The map is now [[1,1]] +myHashMap.get(2); // return -1 (i.e., not found), The map is now [[1,1]] +``` + +**Note**: + +- `0 <= key, value <= 10^6` +- At most `10^4` calls will be made to `put`, `get`, and `remove`. +- Please do not use the built-in HashMap library. + + +### 题目大意 + +不使用任何内建的哈希表库设计一个哈希映射(HashMap)。 + +实现 `MyHashMap` 类: + +- `MyHashMap()` 用空映射初始化对象 +- `void put(int key, int value)` 向 `HashMap` 插入一个键值对 `(key, value)` 。如果 `key` 已经存在于映射中,则更新其对应的值 `value` 。 +- `int get(int key)` 返回特定的 `key` 所映射的 `value` ;如果映射中不包含 `key` 的映射,返回 `-1` 。 +- `void remove(key)` 如果映射中存在 `key` 的映射,则移除 `key` 和它所对应的 `value` 。 + +### 解题思路 + +本题与 [第 705 题](./0705.md) 解法接近,唯一的区别在于存储的不是 `key` 本身,而是 `(key,value)` 对,其他代码都一样。 + +链地址法: + +- 设哈希表的大小为 `base`,则可以设计一个简单的哈希函数:`hash(x) = x mod base`; +- 开辟一个大小为 `base` 的数组,数组的每个位置是一个链表。当计算出哈希值之后,就插入到对应位置的链表当中; +- 由于使用整数除法作为哈希函数,为了尽可能避免冲突,应当将 `base` 取为一个质数,如 `base = 769`; + +![](../../../assets/images/705.png) + +- 时间复杂度:`O(n / b)`。其中 `n` 为哈希表中的元素数量,`b` 为链表的数量,假设哈希值是均匀分布的,则每个链表大概长度为 `n / b`; +- 空间复杂度:`O(n+b)`。 + +### 代码 + +```javascript +class MyHashMap { + constructor () { + this.base = 769 + this.data = new Array(this.base).fill(0).map(() => new Array()) + } + + // @param {number} key + // @return {number} + hash (key) { + return key % this.base + } + + // @param {number} key + // @param {number} value + // @return {void} + put (key, value) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item[0] === key) { + item[1] = value + return + } + } + this.data[h].push([key, value]) + } + + // @param {number} key + // @return {number} + get (key) { + const h = this.hash(key) + for (let item of this.data[h]) { + if (item[0] === key) return item[1] + } + return -1 + } + + // @param {number} key + // @return {void} + remove (key) { + const h = this.hash(key) + const hList = this.data[h] + for (let i = 0; i < hList.length; i++) { + if (hList[i][0] === key) { + hList.splice(i, 1) + return + } + } + } +} +/** + * Your MyHashMap object will be instantiated and called as such: + * var obj = new MyHashMap() + * obj.put(key,value) + * var param_2 = obj.get(key) + * obj.remove(key) + */ +``` diff --git a/docs/leetcode/problem/0707.md b/docs/leetcode/problem/0707.md index 645dcecf43..345377479c 100644 --- a/docs/leetcode/problem/0707.md +++ b/docs/leetcode/problem/0707.md @@ -1,6 +1,6 @@ # [707. Design Linked List](https://leetcode.com/problems/design-linked-list/) -🟠 Medium  🔖  [`设计`](../solution/design.md) [`链表`](../solution/linked-list.md) +🍊 Medium  🔖  [`设计`](../solution/design.md) [`链表`](../solution/linked-list.md) ### 题目 diff --git a/docs/leetcode/problem/0724.md b/docs/leetcode/problem/0724.md index 3f876e6f1a..78afdb5dea 100644 --- a/docs/leetcode/problem/0724.md +++ b/docs/leetcode/problem/0724.md @@ -1,6 +1,6 @@ # [724. Find Pivot Index](https://leetcode.com/problems/find-pivot-index/) -🟢 Esay  🔖  [`数组`](../solution/array.md) [`前缀和`](../solution/prefix-sum.md) +🍏 Esay  🔖  [`数组`](../solution/array.md) [`前缀和`](../solution/prefix-sum.md) ### 题目 diff --git a/docs/leetcode/problem/0739.md b/docs/leetcode/problem/0739.md index 2f8b829591..a64b9d9b3e 100644 --- a/docs/leetcode/problem/0739.md +++ b/docs/leetcode/problem/0739.md @@ -1,6 +1,6 @@ # [739. Daily Temperatures](https://leetcode.com/problems/daily-temperatures/) -🟠 Medium  🔖  [`栈`](../solution/stack.md) [`数组`](../solution/array.md) [`单调栈`](../solution/monotonic-stack.md) +🍊 Medium  🔖  [`栈`](../solution/stack.md) [`数组`](../solution/array.md) [`单调栈`](../solution/monotonic-stack.md) ### 题目 diff --git a/docs/leetcode/problem/0876.md b/docs/leetcode/problem/0876.md index 84f4b65945..97891843c8 100644 --- a/docs/leetcode/problem/0876.md +++ b/docs/leetcode/problem/0876.md @@ -1,6 +1,6 @@ # [876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/) -🟢 Esay  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) +🍏 Esay  🔖  [`链表`](../solution/linked-list.md) [`双指针`](../solution/two-pointers.md) ### 题目 diff --git a/docs/leetcode/problem/1047.md b/docs/leetcode/problem/1047.md index 9301b56302..7ebe5da277 100644 --- a/docs/leetcode/problem/1047.md +++ b/docs/leetcode/problem/1047.md @@ -1,6 +1,6 @@ # [1047. Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) -🟢 Esay  🔖  [`栈`](../solution/stack.md) [`字符串`](../solution/string.md) +🍏 Esay  🔖  [`栈`](../solution/stack.md) [`字符串`](../solution/string.md) ### 题目 diff --git a/docs/leetcode/problem/i_03.01.md b/docs/leetcode/problem/i_03.01.md index 61d543cbfc..fa5753d4e0 100644 --- a/docs/leetcode/problem/i_03.01.md +++ b/docs/leetcode/problem/i_03.01.md @@ -1,5 +1,5 @@ # [面试题 03.01. 三合一](https://leetcode.cn/problems/three-in-one-lcci/) -🟢 Esay  🔖  [`栈`](../solution/stack.md) [`设计`](../solution/design.md) [`数组`](../solution/array.md) +🍏 Esay  🔖  [`栈`](../solution/stack.md) [`设计`](../solution/design.md) [`数组`](../solution/array.md) ### 题目 diff --git a/docs/leetcode/solution/0700-0799.md b/docs/leetcode/solution/0700-0799.md index 061e35d95c..571aebdb84 100644 --- a/docs/leetcode/solution/0700-0799.md +++ b/docs/leetcode/solution/0700-0799.md @@ -6,6 +6,8 @@ title: "索引" | 题号 | 标题 | 题解 | 标签 | 难度 | | :------: | :------ | :------: | :------ | :------ | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0707 | [设计链表](https://leetcode.com/problems/design-linked-list/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0707) | `设计` `链表` | Medium | | 0724 | [寻找数组的中心下标](https://leetcode.com/problems/find-pivot-index/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0724) | `数组` `前缀和` | Esay | | 0739 | [每日温度](https://leetcode.com/problems/daily-temperatures/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0739) | `栈` `数组` `单调栈` | Medium | \ No newline at end of file diff --git a/docs/leetcode/solution/array.md b/docs/leetcode/solution/array.md index 6d2da2054b..68d512b49c 100644 --- a/docs/leetcode/solution/array.md +++ b/docs/leetcode/solution/array.md @@ -399,8 +399,8 @@ table th:nth-of-type(5) { width: 10%; } | 0699 | [掉落的方块](https://leetcode.com/problems/falling-squares/) | | `线段树` `数组` `有序集合` | Hard | | 0702 | [搜索长度未知的有序数组](https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size/) | | `数组` `二分查找` `交互` | Medium | | 0704 | [二分查找](https://leetcode.com/problems/binary-search/) | | `数组` `二分查找` | Esay | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0710 | [黑名单中的随机数](https://leetcode.com/problems/random-pick-with-blacklist/) | | `数组` `哈希表` `数学` `3+` | Hard | | 0713 | [乘积小于 K 的子数组](https://leetcode.com/problems/subarray-product-less-than-k/) | | `数组` `滑动窗口` | Medium | | 0714 | [买卖股票的最佳时机含手续费](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/) | | `贪心` `数组` | Medium | diff --git a/docs/leetcode/solution/design.md b/docs/leetcode/solution/design.md index d8e74fde72..1cef808ff3 100644 --- a/docs/leetcode/solution/design.md +++ b/docs/leetcode/solution/design.md @@ -147,8 +147,8 @@ table th:nth-of-type(5) { width: 10%; } | 0676 | [实现一个魔法字典](https://leetcode.com/problems/implement-magic-dictionary/) | | `设计` `字典树` `哈希表` `1+` | Medium | | 0677 | [键值映射](https://leetcode.com/problems/map-sum-pairs/) | | `设计` `字典树` `哈希表` `1+` | Medium | | 0703 | [数据流中的第 K 大元素](https://leetcode.com/problems/kth-largest-element-in-a-stream/) | | `树` `设计` `二叉搜索树` `3+` | Esay | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0707 | [设计链表](https://leetcode.com/problems/design-linked-list/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0707) | `设计` `链表` | Medium | | 0715 | [Range 模块](https://leetcode.com/problems/range-module/) | | `设计` `线段树` `有序集合` | Hard | | 0716 | [最大栈](https://leetcode.com/problems/max-stack/) | | `栈` `设计` `链表` `2+` | Hard | diff --git a/docs/leetcode/solution/hash-function.md b/docs/leetcode/solution/hash-function.md index 5726c10100..4a25d8010b 100644 --- a/docs/leetcode/solution/hash-function.md +++ b/docs/leetcode/solution/hash-function.md @@ -106,8 +106,8 @@ table th:nth-of-type(5) { width: 10%; } | 0535 | [TinyURL 的加密与解密](https://leetcode.com/problems/encode-and-decode-tinyurl/) | | `设计` `哈希表` `字符串` `1+` | Medium | | 0572 | [另一棵树的子树](https://leetcode.com/problems/subtree-of-another-tree/) | | `树` `深度优先搜索` `二叉树` `2+` | Esay | | 0694 | [不同岛屿的数量](https://leetcode.com/problems/number-of-distinct-islands/) | | `深度优先搜索` `广度优先搜索` `并查集` `2+` | Medium | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0711 | [不同岛屿的数量 II](https://leetcode.com/problems/number-of-distinct-islands-ii/) | | `深度优先搜索` `广度优先搜索` `并查集` `2+` | Hard | | 0718 | [最长重复子数组](https://leetcode.com/problems/maximum-length-of-repeated-subarray/) | | `数组` `二分查找` `动态规划` `3+` | Medium | | 1044 | [最长重复子串](https://leetcode.com/problems/longest-duplicate-substring/) | | `字符串` `二分查找` `后缀数组` `3+` | Hard | diff --git a/docs/leetcode/solution/hash-table.md b/docs/leetcode/solution/hash-table.md index 4b1a2d02ec..2c957d7022 100644 --- a/docs/leetcode/solution/hash-table.md +++ b/docs/leetcode/solution/hash-table.md @@ -224,8 +224,8 @@ table th:nth-of-type(5) { width: 10%; } | 0692 | [前K个高频单词](https://leetcode.com/problems/top-k-frequent-words/) | | `字典树` `哈希表` `字符串` `4+` | Medium | | 0694 | [不同岛屿的数量](https://leetcode.com/problems/number-of-distinct-islands/) | | `深度优先搜索` `广度优先搜索` `并查集` `2+` | Medium | | 0697 | [数组的度](https://leetcode.com/problems/degree-of-an-array/) | | `数组` `哈希表` | Esay | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0710 | [黑名单中的随机数](https://leetcode.com/problems/random-pick-with-blacklist/) | | `数组` `哈希表` `数学` `3+` | Hard | | 0711 | [不同岛屿的数量 II](https://leetcode.com/problems/number-of-distinct-islands-ii/) | | `深度优先搜索` `广度优先搜索` `并查集` `2+` | Hard | | 0720 | [词典中最长的单词](https://leetcode.com/problems/longest-word-in-dictionary/) | | `字典树` `数组` `哈希表` `2+` | Medium | diff --git a/docs/leetcode/solution/linked-list.md b/docs/leetcode/solution/linked-list.md index 3d088a75e0..1a0803d218 100644 --- a/docs/leetcode/solution/linked-list.md +++ b/docs/leetcode/solution/linked-list.md @@ -140,8 +140,8 @@ table th:nth-of-type(5) { width: 10%; } | 0460 | [LFU 缓存](https://leetcode.com/problems/lfu-cache/) | | `设计` `哈希表` `链表` `1+` | Hard | | 0622 | [设计循环队列](https://leetcode.com/problems/design-circular-queue/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0622) | `设计` `队列` `数组` `1+` | Medium | | 0641 | [设计循环双端队列](https://leetcode.com/problems/design-circular-deque/) | | `设计` `队列` `数组` `1+` | Medium | -| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | | `设计` `数组` `哈希表` `2+` | Esay | -| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | | `设计` `数组` `哈希表` `2+` | Esay | +| 0705 | [设计哈希集合](https://leetcode.com/problems/design-hashset/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0705) | `设计` `数组` `哈希表` `2+` | Esay | +| 0706 | [设计哈希映射](https://leetcode.com/problems/design-hashmap/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0706) | `设计` `数组` `哈希表` `2+` | Esay | | 0707 | [设计链表](https://leetcode.com/problems/design-linked-list/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/0707) | `设计` `链表` | Medium | | 0708 | [循环有序列表的插入](https://leetcode.com/problems/insert-into-a-sorted-circular-linked-list/) | | `链表` | Medium | | 0716 | [最大栈](https://leetcode.com/problems/max-stack/) | | `栈` `设计` `链表` `2+` | Hard | diff --git a/package.json b/package.json index c9a2f7dd3b..0aef51ec27 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "scripts": { "dev": "vuepress dev docs", "build": "vuepress build docs", - "lc": "cd ./assets/scripts & py ./create_table.py" + "lc": "cd ./assets/scripts & py ./entrance.py" }, "dependencies": { "element-ui": "^2.10.1"