Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d8ea13e

Browse filesBrowse files
committed
add 7 solutions
1 parent 9431f7a commit d8ea13e
Copy full SHA for d8ea13e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

51 files changed

+1195
-621
lines changed

‎assets/scripts/gen-docs.py

Copy file name to clipboardExpand all lines: assets/scripts/gen-docs.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ def gen_solution_list():
2929
if not df_indexs:
3030
print('%s 没有出现在 problem-list.csv 中' % (Path(file).stem))
3131
continue
32-
3332
res = utils.gen_frame_items(df_indexs[0], df)
3433
frame.loc[frame_count] = res
3534
frame_count += 1
3635

3736
table = utils.gen_markdown_table(frame)
38-
content = "已完成 {} 道\n\n".format(frame_count) + table + "\n\n"
37+
content = "已完成 {} 道\n\n".format(frame_count) + table + "\n\n由于编译限制,本目录只展示 800 道。\n\n"
3938

4039
with open(const.problem_readme, 'w', encoding='utf-8') as f:
4140
f.writelines("# 目录\n\n")

‎assets/scripts/utils.py

Copy file name to clipboardExpand all lines: assets/scripts/utils.py
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def custom_sort(val):
2121

2222
def gen_markdown_table(frame, need_sort = True):
2323

24-
H = frame.shape[0]
2524
W = frame.shape[1]
2625

2726
head_name = ["题号", "标题", "题解", "标签", "难度", "力扣", "频次"]
@@ -44,11 +43,18 @@ def gen_markdown_table(frame, need_sort = True):
4443
else:
4544
line = "{} {} |".format(line, SPLIT2.format('-'*6))
4645
lines += [line]
47-
46+
4847
# 数据部分
4948
if need_sort:
5049
frame = frame.sort_values(by='题号', key=lambda col: col.apply(custom_sort))
5150
frame = frame.reset_index(drop=True)
51+
52+
53+
# 限制表格中的题数,文件太大会部署失败
54+
if len(frame) > 500:
55+
frame = frame.head(500)
56+
H = frame.shape[0]
57+
5258
for i in range(H):
5359
problem = "|"
5460
for j in range(W):

‎src/.vuepress/sidebar.ts

Copy file name to clipboardExpand all lines: src/.vuepress/sidebar.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ export default sidebar({
720720
"1351",
721721
"1352",
722722
"1356",
723+
"1358",
723724
"1360",
724725
"1365",
725726
"1370",
@@ -1099,6 +1100,7 @@ export default sidebar({
10991100
"2501",
11001101
"2516",
11011102
"2523",
1103+
"2529",
11021104
"2530",
11031105
"2542",
11041106
"2554",
@@ -1268,6 +1270,7 @@ export default sidebar({
12681270
"collapsible": true,
12691271
"children": [
12701272
"3203",
1273+
"3208",
12711274
"3223",
12721275
"3243",
12731276
"3264"
@@ -1277,10 +1280,12 @@ export default sidebar({
12771280
"text": "3300-3399",
12781281
"collapsible": true,
12791282
"children": [
1283+
"3306",
12801284
"3309",
12811285
"3318",
12821286
"3319",
1283-
"3321"
1287+
"3321",
1288+
"3356"
12841289
]
12851290
}
12861291

‎src/book/slide_window.md

Copy file name to clipboardExpand all lines: src/book/slide_window.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ var lengthOfLongestSubstring = function (s) {
589589
| 992 | K 个不同整数的子数组 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`计数`](/tag/counting.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/subarrays-with-k-different-integers) [🔗](https://leetcode.com/problems/subarrays-with-k-different-integers) |
590590
| 713 | 乘积小于 K 的子数组 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`前缀和`](/tag/prefix-sum.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/subarray-product-less-than-k) [🔗](https://leetcode.com/problems/subarray-product-less-than-k) |
591591
| 904 | 水果成篮 | | [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/fruit-into-baskets) [🔗](https://leetcode.com/problems/fruit-into-baskets) |
592-
| 1358 | 包含所有三种字符的子字符串数目 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-substrings-containing-all-three-characters) [🔗](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters) |
592+
| 1358 | 包含所有三种字符的子字符串数目 | [[]](/problem/1358.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-substrings-containing-all-three-characters) [🔗](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters) |
593593
| 467 | 环绕字符串中唯一的子字符串 | [[]](/problem/0467.md) | [`字符串`](/tag/string.md) [`动态规划`](/tag/dynamic-programming.md) | 🟠 | [🀄️](https://leetcode.cn/problems/unique-substrings-in-wraparound-string) [🔗](https://leetcode.com/problems/unique-substrings-in-wraparound-string) |
594594
| 1438 | 绝对差不超过限制的最长连续子数组 | | [`队列`](/tag/queue.md) [`数组`](/tag/array.md) [`有序集合`](/tag/ordered-set.md) `3+` | 🟠 | [🀄️](https://leetcode.cn/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) [🔗](https://leetcode.com/problems/longest-continuous-subarray-with-absolute-diff-less-than-or-equal-to-limit) |
595595

‎src/plan/contest_list.md

Copy file name to clipboardExpand all lines: src/plan/contest_list.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ headerDepth: 0
6161
| :------: | :------ | :------: | :------ | :------: | :------: |
6262
| 3304 | 找出第 K 个字符 I | | [`位运算`](/tag/bit-manipulation.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/find-the-k-th-character-in-string-game-i) [🔗](https://leetcode.com/problems/find-the-k-th-character-in-string-game-i) |
6363
| 3305 | 元音辅音字符串计数 I | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i) [🔗](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-i) |
64-
| 3306 | 元音辅音字符串计数 II | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii) [🔗](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii) |
64+
| 3306 | 元音辅音字符串计数 II | [[✓]](/problem/3306.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii) [🔗](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii) |
6565
| 3307 | 找出第 K 个字符 II | | [`位运算`](/tag/bit-manipulation.md) [`递归`](/tag/recursion.md) [`数学`](/tag/math.md) | 🔴 | [🀄️](https://leetcode.cn/problems/find-the-k-th-character-in-string-game-ii) [🔗](https://leetcode.com/problems/find-the-k-th-character-in-string-game-ii) |
6666

6767

@@ -289,7 +289,7 @@ headerDepth: 0
289289
| :------: | :------ | :------: | :------ | :------: | :------: |
290290
| 3206 | 交替组 I | | [`数组`](/tag/array.md) [`滑动窗口`](/tag/sliding-window.md) | 🟢 | [🀄️](https://leetcode.cn/problems/alternating-groups-i) [🔗](https://leetcode.com/problems/alternating-groups-i) |
291291
| 3207 | 与敌人战斗后的最大分数 | | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximum-points-after-enemy-battles) [🔗](https://leetcode.com/problems/maximum-points-after-enemy-battles) |
292-
| 3208 | 交替组 II | | [`数组`](/tag/array.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/alternating-groups-ii) [🔗](https://leetcode.com/problems/alternating-groups-ii) |
292+
| 3208 | 交替组 II | [[✓]](/problem/3208.md) | [`数组`](/tag/array.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/alternating-groups-ii) [🔗](https://leetcode.com/problems/alternating-groups-ii) |
293293
| 3209 | 子数组按位与值为 K 的数目 | | [`位运算`](/tag/bit-manipulation.md) [`线段树`](/tag/segment-tree.md) [`数组`](/tag/array.md) `1+` | 🔴 | [🀄️](https://leetcode.cn/problems/number-of-subarrays-with-and-value-of-k) [🔗](https://leetcode.com/problems/number-of-subarrays-with-and-value-of-k) |
294294

295295

@@ -1679,7 +1679,7 @@ headerDepth: 0
16791679
<!-- prettier-ignore -->
16801680
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
16811681
| :------: | :------ | :------: | :------ | :------: | :------: |
1682-
| 2529 | 正整数和负整数的最大计数 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer) [🔗](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) |
1682+
| 2529 | 正整数和负整数的最大计数 | [[✓]](/problem/2529.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer) [🔗](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) |
16831683
| 2530 | 执行 K 次操作后的最大分数 | [[✓]](/problem/2530.md) | [`贪心`](/tag/greedy.md) [`数组`](/tag/array.md) [`堆(优先队列)`](/tag/heap-priority-queue.md) | 🟠 | [🀄️](https://leetcode.cn/problems/maximal-score-after-applying-k-operations) [🔗](https://leetcode.com/problems/maximal-score-after-applying-k-operations) |
16841684
| 2531 | 使字符串中不同字符的数目相等 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) | 🟠 | [🀄️](https://leetcode.cn/problems/make-number-of-distinct-characters-equal) [🔗](https://leetcode.com/problems/make-number-of-distinct-characters-equal) |
16851685
| 2532 | 过桥的时间 | | [`数组`](/tag/array.md) [`模拟`](/tag/simulation.md) [`堆(优先队列)`](/tag/heap-priority-queue.md) | 🔴 | [🀄️](https://leetcode.cn/problems/time-to-cross-a-bridge) [🔗](https://leetcode.com/problems/time-to-cross-a-bridge) |
@@ -4393,7 +4393,7 @@ headerDepth: 0
43934393
| :------: | :------ | :------: | :------ | :------: | :------: |
43944394
| 1356 | 根据数字二进制下 1 的数目排序 | [[✓]](/problem/1356.md) | [`位运算`](/tag/bit-manipulation.md) [`数组`](/tag/array.md) [`计数`](/tag/counting.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/sort-integers-by-the-number-of-1-bits) [🔗](https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits) |
43954395
| 1357 | 每隔 n 个顾客打折 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`哈希表`](/tag/hash-table.md) | 🟠 | [🀄️](https://leetcode.cn/problems/apply-discount-every-n-orders) [🔗](https://leetcode.com/problems/apply-discount-every-n-orders) |
4396-
| 1358 | 包含所有三种字符的子字符串数目 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-substrings-containing-all-three-characters) [🔗](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters) |
4396+
| 1358 | 包含所有三种字符的子字符串数目 | [[✓]](/problem/1358.md) | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`滑动窗口`](/tag/sliding-window.md) | 🟠 | [🀄️](https://leetcode.cn/problems/number-of-substrings-containing-all-three-characters) [🔗](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters) |
43974397
| 1359 | 有效的快递序列数目 | | [`数学`](/tag/math.md) [`动态规划`](/tag/dynamic-programming.md) [`组合数学`](/tag/combinatorics.md) | 🔴 | [🀄️](https://leetcode.cn/problems/count-all-valid-pickup-and-delivery-options) [🔗](https://leetcode.com/problems/count-all-valid-pickup-and-delivery-options) |
43984398

43994399

‎src/problem/0121.md

Copy file name to clipboardExpand all lines: src/problem/0121.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ cannot achieve any profit, return `0`.
7979

8080
### 思路一:动态规划
8181

82-
1. **动态规划:**定义一个二维数组 `dp`,其中 `dp[i][0]` 表示第 `i` 天不持有股票时的最大利润, `dp[i][1]` 表示第 `i` 天持有股票时的最大利润。
82+
1. **动态规划:** 定义一个二维数组 `dp`,其中 `dp[i][0]` 表示第 `i` 天不持有股票时的最大利润, `dp[i][1]` 表示第 `i` 天持有股票时的最大利润。
8383
2. **状态转移方程:**
8484

8585
- `dp[i][0] = max(dp[i-1][0], dp[i-1][1] + prices[i])`,表示在第 `i` 天,不持有股票的最大利润等于前一天不持有股票的最大利润,或者前一天持有股票的最大利润加上今天卖出的利润的最大值。
8686
- `dp[i][1] = max(dp[i-1][1], -prices[i])`,表示在第 `i` 天,持有股票的最大利润等于前一天持有股票的最大利润,或者前一天不持有股票的最大利润减去今天买入的利润的最大值。由于题目规定只能买入一次,所以前一天不持有股票的最大利润为 0。
8787

88-
3. **边界条件:**第一天(`i == 0`)时,`dp[0][0] = 0``dp[0][1] = -prices[0]`
89-
4. **初始化:**初始化利润为 0。
90-
5. **返回最大利润:**最后返回 `dp[n - 1][0]`,即最后一天不持有股票的最大利润,因为若最后一天还持有股票没有卖出,收益肯定小于做了一次交易的情况。
88+
3. **边界条件:** 第一天(`i == 0`)时,`dp[0][0] = 0``dp[0][1] = -prices[0]`
89+
4. **初始化:** 初始化利润为 0。
90+
5. **返回最大利润:** 最后返回 `dp[n - 1][0]`,即最后一天不持有股票的最大利润,因为若最后一天还持有股票没有卖出,收益肯定小于做了一次交易的情况。
9191

9292
#### 复杂度分析
9393

‎src/problem/0494.md

Copy file name to clipboardExpand all lines: src/problem/0494.md
+8-12Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,15 @@ var findTargetSumWays = function (nums, target) {
225225
const sum = nums.reduce((num, acc) => num + acc, 0);
226226
if (sum < target || -sum > target || (sum + target) % 2 == 1) return 0;
227227

228-
const subset = (nums, sum) => {
229-
const dp = new Array(sum + 1).fill(0);
230-
dp[0] = 1;
231-
for (let num of nums) {
232-
for (let j = sum; j >= 0; j--) {
233-
if (j >= num) {
234-
dp[j] = dp[j - num] + dp[j];
235-
}
236-
}
228+
const n = (sum + target) / 2;
229+
const dp = new Array(n + 1).fill(0);
230+
dp[0] = 1;
231+
for (let num of nums) {
232+
for (let i = n; i >= num; i--) {
233+
dp[i] += dp[i - num];
237234
}
238-
return dp[sum];
239-
};
240-
return subset(nums, (sum + target) / 2);
235+
}
236+
return dp[n];
241237
};
242238
```
243239

‎src/problem/0704.md

Copy file name to clipboardExpand all lines: src/problem/0704.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ var search = function (nums, target) {
100100
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
101101
| :------: | :------ | :------: | :------ | :------: | :------: |
102102
| 702 | 搜索长度未知的有序数组 🔒 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`交互`](/tag/interactive.md) | 🟠 | [🀄️](https://leetcode.cn/problems/search-in-a-sorted-array-of-unknown-size) [🔗](https://leetcode.com/problems/search-in-a-sorted-array-of-unknown-size) |
103-
| 2529 | 正整数和负整数的最大计数 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer) [🔗](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) |
103+
| 2529 | 正整数和负整数的最大计数 | [[]](/problem/2529.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer) [🔗](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) |

‎src/problem/1351.md

Copy file name to clipboardExpand all lines: src/problem/1351.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,4 @@ var countNegatives = function (grid) {
166166
<!-- prettier-ignore -->
167167
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
168168
| :------: | :------ | :------: | :------ | :------: | :------: |
169-
| 2529 | 正整数和负整数的最大计数 | | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer) [🔗](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) |
169+
| 2529 | 正整数和负整数的最大计数 | [[]](/problem/2529.md) | [`数组`](/tag/array.md) [`二分查找`](/tag/binary-search.md) [`计数`](/tag/counting.md) | 🟢 | [🀄️](https://leetcode.cn/problems/maximum-count-of-positive-integer-and-negative-integer) [🔗](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer) |

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.