Skip to content

Commit e1a0800

Browse files
committed
add 1497
1 parent fe40ec5 commit e1a0800

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+1354
-829
lines changed

assets/output/1497.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/.vuepress/sidebar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ export default sidebar({
442442
children: [
443443
"1441",
444444
"1472",
445-
"1475"
445+
"1475",
446+
"1497"
446447
],
447448
},
448449
{

src/leetcode/outline/solution_list.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 1.3 LeetCode 题解
22

3-
已完成 366
3+
已完成 367
44

55
| 题号 | 标题 | 题解 | 标签 | 难度 |
66
| :------: | :------ | :------: | :------ | :------ |
@@ -307,6 +307,7 @@
307307
| 1441 | [用栈操作构建数组](https://leetcode.com/problems/build-an-array-with-stack-operations/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1441) | [``](/leetcode/outline/tag/stack.md) [`数组`](/leetcode/outline/tag/array.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#ffb800>Medium</font> |
308308
| 1472 | [设计浏览器历史记录](https://leetcode.com/problems/design-browser-history/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1472) | [``](/leetcode/outline/tag/stack.md) [`设计`](/leetcode/outline/tag/design.md) [`数组`](/leetcode/outline/tag/array.md) `3+` | <font color=#ffb800>Medium</font> |
309309
| 1475 | [商品折扣后的最终价格](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1475) | [``](/leetcode/outline/tag/stack.md) [`数组`](/leetcode/outline/tag/array.md) [`单调栈`](/leetcode/outline/tag/monotonic-stack.md) | <font color=#15bd66>Easy</font> |
310+
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1497) | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
310311
| 1522 | [N 叉树的直径](https://leetcode.com/problems/diameter-of-n-ary-tree/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1522) | [``](/leetcode/outline/tag/tree.md) [`深度优先搜索`](/leetcode/outline/tag/depth-first-search.md) | <font color=#ffb800>Medium</font> |
311312
| 2196 | [根据描述创建二叉树](https://leetcode.com/problems/create-binary-tree-from-descriptions/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/2196) | [``](/leetcode/outline/tag/tree.md) [`深度优先搜索`](/leetcode/outline/tag/depth-first-search.md) [`广度优先搜索`](/leetcode/outline/tag/breadth-first-search.md) `3+` | <font color=#ffb800>Medium</font> |
312313
| 2259 | [移除指定数字得到的最大结果](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/2259) | [`贪心`](/leetcode/outline/tag/greedy.md) [`字符串`](/leetcode/outline/tag/string.md) [`枚举`](/leetcode/outline/tag/enumeration.md) | <font color=#15bd66>Easy</font> |

src/leetcode/outline/tag/array.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@
719719
| 1488 | [避免洪水泛滥](https://leetcode.com/problems/avoid-flood-in-the-city/) | | [`贪心`](/leetcode/outline/tag/greedy.md) [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) `2+` | <font color=#ffb800>Medium</font> |
720720
| 1491 | [去掉最低工资和最高工资后的工资平均值](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/) | | [`数组`](/leetcode/outline/tag/array.md) [`排序`](/leetcode/outline/tag/sorting.md) | <font color=#15bd66>Easy</font> |
721721
| 1493 | [删掉一个元素以后全为 1 的最长子数组](https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/) | | [`数组`](/leetcode/outline/tag/array.md) [`动态规划`](/leetcode/outline/tag/dynamic-programming.md) [`滑动窗口`](/leetcode/outline/tag/sliding-window.md) | <font color=#ffb800>Medium</font> |
722-
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
722+
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1497) | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
723723
| 1498 | [满足条件的子序列数目](https://leetcode.com/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/) | | [`数组`](/leetcode/outline/tag/array.md) [`双指针`](/leetcode/outline/tag/two-pointers.md) [`二分查找`](/leetcode/outline/tag/binary-search.md) `1+` | <font color=#ffb800>Medium</font> |
724724
| 1499 | [满足不等式的最大值](https://leetcode.com/problems/max-value-of-equation/) | | [`队列`](/leetcode/outline/tag/queue.md) [`数组`](/leetcode/outline/tag/array.md) [`滑动窗口`](/leetcode/outline/tag/sliding-window.md) `2+` | <font color=#ff334b>Hard</font> |
725725
| 1502 | [判断能否形成等差数列](https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/) | | [`数组`](/leetcode/outline/tag/array.md) [`排序`](/leetcode/outline/tag/sorting.md) | <font color=#15bd66>Easy</font> |

src/leetcode/outline/tag/counting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
| 1400 | [构造 K 个回文字符串](https://leetcode.com/problems/construct-k-palindrome-strings/) | | [`贪心`](/leetcode/outline/tag/greedy.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`字符串`](/leetcode/outline/tag/string.md) `1+` | <font color=#ffb800>Medium</font> |
5959
| 1419 | [数青蛙](https://leetcode.com/problems/minimum-number-of-frogs-croaking/) | | [`字符串`](/leetcode/outline/tag/string.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
6060
| 1481 | [不同整数的最少数目](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/) | | [`贪心`](/leetcode/outline/tag/greedy.md) [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) `2+` | <font color=#ffb800>Medium</font> |
61-
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
61+
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1497) | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
6262
| 1512 | [好数对的数目](https://leetcode.com/problems/number-of-good-pairs/) | | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`数学`](/leetcode/outline/tag/mathematics.md) `1+` | <font color=#15bd66>Easy</font> |
6363
| 1519 | [子树中标签相同的节点数](https://leetcode.com/problems/number-of-nodes-in-the-sub-tree-with-the-same-label/) | | [``](/leetcode/outline/tag/tree.md) [`深度优先搜索`](/leetcode/outline/tag/depth-first-search.md) [`广度优先搜索`](/leetcode/outline/tag/breadth-first-search.md) `2+` | <font color=#ffb800>Medium</font> |
6464
| 1603 | [设计停车系统](https://leetcode.com/problems/design-parking-system/) | | [`设计`](/leetcode/outline/tag/design.md) [`计数`](/leetcode/outline/tag/counting.md) [`模拟`](/leetcode/outline/tag/simulation.md) | <font color=#15bd66>Easy</font> |

src/leetcode/outline/tag/hash-table.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
| 1488 | [避免洪水泛滥](https://leetcode.com/problems/avoid-flood-in-the-city/) | | [`贪心`](/leetcode/outline/tag/greedy.md) [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) `2+` | <font color=#ffb800>Medium</font> |
291291
| 1490 | [克隆 N 叉树](https://leetcode.com/problems/clone-n-ary-tree/) | | [``](/leetcode/outline/tag/tree.md) [`深度优先搜索`](/leetcode/outline/tag/depth-first-search.md) [`广度优先搜索`](/leetcode/outline/tag/breadth-first-search.md) `1+` | <font color=#ffb800>Medium</font> |
292292
| 1496 | [判断路径是否相交](https://leetcode.com/problems/path-crossing/) | | [`哈希表`](/leetcode/outline/tag/hash-table.md) [`字符串`](/leetcode/outline/tag/string.md) | <font color=#15bd66>Easy</font> |
293-
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
293+
| 1497 | [检查数组对是否可以被 k 整除](https://leetcode.com/problems/check-if-array-pairs-are-divisible-by-k/) | [JS](https://2xiao.github.io/leetcode-js/leetcode/problem/1497) | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`计数`](/leetcode/outline/tag/counting.md) | <font color=#ffb800>Medium</font> |
294294
| 1500 | [设计文件分享系统](https://leetcode.com/problems/design-a-file-sharing-system/) | | [`设计`](/leetcode/outline/tag/design.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`数据流`](/leetcode/outline/tag/data-streams.md) `1+` | <font color=#ffb800>Medium</font> |
295295
| 1506 | [找到 N 叉树的根节点](https://leetcode.com/problems/find-root-of-n-ary-tree/) | | [`位运算`](/leetcode/outline/tag/bit-manipulation.md) [``](/leetcode/outline/tag/tree.md) [`深度优先搜索`](/leetcode/outline/tag/depth-first-search.md) `1+` | <font color=#ffb800>Medium</font> |
296296
| 1512 | [好数对的数目](https://leetcode.com/problems/number-of-good-pairs/) | | [`数组`](/leetcode/outline/tag/array.md) [`哈希表`](/leetcode/outline/tag/hash-table.md) [`数学`](/leetcode/outline/tag/mathematics.md) `1+` | <font color=#15bd66>Easy</font> |

src/leetcode/problem/0001.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ time complexity?
4747

4848
## 解题思路
4949

50-
这道题最优的做法时间复杂度是 `O(n)`
51-
5250
使用哈希表,顺序扫描数组,对每一个元素,在 `object` 中找能组合给定值的另一半数字,如果找到了,直接返回 2 个数字的下标即可。如果找不到,就把这个数字存入 `object` 中,等待扫到“另一半”数字的时候,再取出来返回结果。
5351

52+
#### 复杂度分析
53+
54+
- **时间复杂度**`O(n)`,其中 `n` 是字符串的长度。
55+
- **空间复杂度**`O(k)`,其中 `k``object` 中存放的数字数量,最坏情况下,需要扫描到最后一个数字才能找到结果,此时 `k` 会趋近 `n`
56+
5457
## 代码
5558

5659
```javascript

src/leetcode/problem/0004.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ The overall run time complexity should be `O(log (m+n))`.
6060
- 如果 k == 1,则返回两个数组的最小值。
6161
- 总长度为偶数时,需要同时找到第 `(m + n) / 2` 和第 `(m + n) / 2 + 1` 小的数,并取它们的平均值作为中位数。
6262

63+
#### 复杂度分析
64+
6365
- **时间复杂度**`O(log(min(m, n)))`,因为每次递归我们会排除掉 `k/2` 个元素,直到找到第 `k` 小的元素,整个过程是对较短数组长度的二分查找。
6466
- **空间复杂度**`O(1)`,只使用了常数级别的额外空间。
6567

src/leetcode/problem/0005.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`.
4444
- **偶数长度的回文串:**
4545
以每两个相邻字符的中心向两边扩展判断回文串。
4646

47-
- 时间复杂度:`O(n^2)`,其中 `n` 是字符串的长度。
48-
- 空间复杂度:`O(1)`
47+
#### 复杂度分析
48+
49+
- **时间复杂度**`O(n^2)`,其中 `n` 是字符串的长度。
50+
- **空间复杂度**`O(1)`
4951

5052
### 思路二:动态规划
5153

@@ -62,8 +64,10 @@ Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`.
6264
- `dp[i][i] = true`
6365
- `s[i] == s[i+1]` 时,`dp[i][i+1] = true`
6466

65-
- 时间复杂度:`O(n^2)`,其中 `n` 是字符串的长度。
66-
- 空间复杂度:`O(n^2)`
67+
#### 复杂度分析
68+
69+
- **时间复杂度**`O(n^2)`,其中 `n` 是字符串的长度。
70+
- **空间复杂度**`O(n^2)`
6771

6872
## 代码
6973

src/leetcode/problem/0014.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ If there is no common prefix, return an empty string `""`.
4141

4242
初始化公共前缀为字符串数组中的第一个字符串,然后将数组中的字符串与公共前缀一依次比较,每次比较出不同时就缩小公共前缀,直到公共前缀为空或者遍历完所有字符串数组。
4343

44-
- 时间复杂度:`O(len(strs[0]))``O(len(strs))`
45-
- 空间复杂度:`O(len(strs[0]))`
44+
#### 复杂度分析
45+
46+
- **时间复杂度**`O(len(strs[0]))``O(len(strs))`
47+
- **空间复杂度**`O(len(strs[0]))`
4648

4749
### 思路二:二维数组
4850

4951
把字符串列表看成一个二维数组,然后用一个嵌套 `for` 循环计算这个二维数组前面有多少列的元素完全相同即可。
5052

51-
- 时间复杂度:`O(mn)`,其中 `m` 是字符串数组中的字符串的平均长度,`n` 是字符串的数量。最坏情况下,字符串数组中的每个字符串的每个字符都会被比较一次。
52-
- 空间复杂度:`O(1)`,使用的额外空间复杂度为常数。
53+
#### 复杂度分析
54+
55+
- **时间复杂度**`O(mn)`,其中 `m` 是字符串数组中的字符串的平均长度,`n` 是字符串的数量。最坏情况下,字符串数组中的每个字符串的每个字符都会被比较一次。
56+
- **空间复杂度**`O(1)`,使用的额外空间复杂度为常数。
5357

5458
## 代码
5559

0 commit comments

Comments
 (0)