Skip to content

Commit 9df5a8f

Browse files
committed
add 25 solutions
1 parent d246039 commit 9df5a8f

Some content is hidden

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

59 files changed

+4465
-316
lines changed

src/.vuepress/sidebar.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,23 +601,47 @@ export default sidebar({
601601
"1232",
602602
"1233",
603603
"1252",
604+
"1260",
605+
"1266",
604606
"1268",
607+
"1275",
605608
"1277",
606-
"1288"
609+
"1281",
610+
"1287",
611+
"1288",
612+
"1290",
613+
"1295",
614+
"1299"
607615
]
608616
},
609617
{
610618
"text": "1300-1399",
611619
"collapsible": true,
612620
"children": [
621+
"1304",
613622
"1312",
623+
"1313",
624+
"1317",
614625
"1318",
626+
"1323",
615627
"1331",
628+
"1332",
629+
"1337",
630+
"1342",
616631
"1346",
617632
"1351",
633+
"1356",
634+
"1360",
635+
"1365",
636+
"1370",
618637
"1372",
638+
"1374",
619639
"1378",
620-
"1381"
640+
"1379",
641+
"1380",
642+
"1381",
643+
"1385",
644+
"1389"
621645
]
622646
},
623647
{
@@ -895,7 +919,8 @@ export default sidebar({
895919
"children": [
896920
"2914",
897921
"2924",
898-
"2938"
922+
"2938",
923+
"2940"
899924
]
900925
},
901926
{
@@ -929,7 +954,6 @@ export default sidebar({
929954
"collapsible": true,
930955
"children": [
931956
"3309",
932-
"3311",
933957
"3318",
934958
"3319",
935959
"3321"

src/plan/contest_list.md

Lines changed: 25 additions & 25 deletions
Large diffs are not rendered by default.

src/plan/top_300_list.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ headerDepth: 0
575575
| 题号 | 标题 | 题解 | 标签 | 难度 | 力扣 |
576576
| :------: | :------ | :------: | :------ | :------: | :------: |
577577
| 1232 | 缀点成线 | [[]](/problem/1232.md) | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/check-if-it-is-a-straight-line) [🔗](https://leetcode.com/problems/check-if-it-is-a-straight-line) |
578-
| 1266 | 访问所有点的最小时间 | | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/minimum-time-visiting-all-points) [🔗](https://leetcode.com/problems/minimum-time-visiting-all-points) |
578+
| 1266 | 访问所有点的最小时间 | [[]](/problem/1266.md) | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🟢 | [🀄️](https://leetcode.cn/problems/minimum-time-visiting-all-points) [🔗](https://leetcode.com/problems/minimum-time-visiting-all-points) |
579579
| 892 | 三维形体的表面积 | [[]](/problem/0892.md) | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/surface-area-of-3d-shapes) [🔗](https://leetcode.com/problems/surface-area-of-3d-shapes) |
580580
| 1401 | 圆和矩形是否有重叠 | | [`几何`](/tag/geometry.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/circle-and-rectangle-overlapping) [🔗](https://leetcode.com/problems/circle-and-rectangle-overlapping) |
581581
| 963 | 最小面积矩形 II | | [`几何`](/tag/geometry.md) [`数组`](/tag/array.md) [`数学`](/tag/math.md) | 🟠 | [🀄️](https://leetcode.cn/problems/minimum-area-rectangle-ii) [🔗](https://leetcode.com/problems/minimum-area-rectangle-ii) |

src/problem/0443.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,6 @@ var compress = function (chars) {
184184
| 38 | 外观数列 | [[]](/problem/0038.md) | [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/count-and-say) [🔗](https://leetcode.com/problems/count-and-say) |
185185
| 271 | 字符串的编码与解码 🔒 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/encode-and-decode-strings) [🔗](https://leetcode.com/problems/encode-and-decode-strings) |
186186
| 604 | 迭代压缩字符串 🔒 | | [`设计`](/tag/design.md) [`数组`](/tag/array.md) [`字符串`](/tag/string.md) `1+` | 🟢 | [🀄️](https://leetcode.cn/problems/design-compressed-string-iterator) [🔗](https://leetcode.com/problems/design-compressed-string-iterator) |
187-
| 1313 | 解压缩编码列表 | | [`数组`](/tag/array.md) | 🟢 | [🀄️](https://leetcode.cn/problems/decompress-run-length-encoded-list) [🔗](https://leetcode.com/problems/decompress-run-length-encoded-list) |
187+
| 1313 | 解压缩编码列表 | [[]](/problem/1313.md) | [`数组`](/tag/array.md) | 🟢 | [🀄️](https://leetcode.cn/problems/decompress-run-length-encoded-list) [🔗](https://leetcode.com/problems/decompress-run-length-encoded-list) |
188188
| 3163 | 压缩字符串 III | [[]](/problem/3163.md) | [`字符串`](/tag/string.md) | 🟠 | [🀄️](https://leetcode.cn/problems/string-compression-iii) [🔗](https://leetcode.com/problems/string-compression-iii) |
189189
| 3167 | 字符串的更好压缩 🔒 | | [`哈希表`](/tag/hash-table.md) [`字符串`](/tag/string.md) [`计数`](/tag/counting.md) `1+` | 🟠 | [🀄️](https://leetcode.cn/problems/better-compression-of-string) [🔗](https://leetcode.com/problems/better-compression-of-string) |

src/problem/0830.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,63 @@ Return _the intervals of every **large** group sorted in **increasing order by s
110110

111111
## 解题思路
112112

113+
可以通过一次遍历字符串,记录连续字符的起点和终点,当字符发生变化时判断这段连续字符的长度是否大于等于 3,从而找到大组。
114+
115+
1. **初始化变量**
116+
117+
- `start` 表示当前连续字符的起始位置。
118+
- 遍历字符串时,用 `end` 表示当前字符的位置。
119+
- 使用结果数组 `res` 存储所有大组的起始和结束位置。
120+
121+
2. **遍历字符串**
122+
123+
- 如果当前字符 `s[end]` 与前一个字符 `s[start]` 不同:
124+
- 检查从 `start``end - 1` 的字符数量是否大于等于 3:
125+
- 如果是,将 `[start, end - 1]` 添加到结果数组。
126+
-`start` 更新为 `end`,即新一段连续字符的起始位置。
127+
128+
3. **处理最后一组字符**
129+
130+
- 如果字符串结尾的最后一组字符长度大于等于 3,将其位置添加到结果数组。
131+
132+
4. **返回结果**
133+
- 返回存储大组位置的数组 `res`
134+
113135
#### 复杂度分析
114136

115-
- **时间复杂度**`O()`
116-
- **空间复杂度**`O()`
137+
- **时间复杂度**`O(n)`其中 `n` 是字符串的长度,遍历字符串一次。
138+
- **空间复杂度**`O(n)`结果数组 `res` 存储所有大组的位置,最坏情况下,所有字符形成一个大组。
117139

118140
## 代码
119141

120142
```javascript
121-
143+
/**
144+
* @param {string} s
145+
* @return {number[][]}
146+
*/
147+
var largeGroupPositions = function (s) {
148+
const n = s.length;
149+
let res = [];
150+
let start = 0;
151+
152+
// 遍历字符串
153+
for (let end = 0; end < n; end++) {
154+
// 当字符变化时,处理当前段
155+
if (s[end] !== s[start]) {
156+
if (end - start > 2) {
157+
res.push([start, end - 1]);
158+
}
159+
start = end; // 更新起始位置
160+
}
161+
}
162+
163+
// 处理最后一组字符
164+
if (n - start > 2) {
165+
res.push([start, n - 1]);
166+
}
167+
168+
return res;
169+
};
122170
```
123171

124172
## 相关题目

src/problem/0946.md

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,83 @@ pop operations on an initially empty stack, or_`false` _otherwise._
5656

5757
## 题目大意
5858

59-
给定 `pushed``popped` 两个序列,每个序列中的 值都不重复,只有当它们可能是在最初空栈上进行的推入 `push` 和弹出 `pop` 操作序列的结果时,返回 `true`;否则,返回 `false`
59+
给定 `pushed``popped` 两个序列,每个序列中的 **值都不重复** ,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop
60+
操作序列的结果时,返回 `true`;否则,返回 `false`
61+
62+
**示例 1:**
63+
64+
> **输入:** pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
65+
>
66+
> **输出:** true
67+
>
68+
> **解释:** 我们可以按以下顺序执行:
69+
>
70+
> push(1), push(2), push(3), push(4), pop() -> 4,
71+
>
72+
> push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
73+
74+
**示例 2:**
75+
76+
> **输入:** pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
77+
>
78+
> **输出:** false
79+
>
80+
> **解释:** 1 不能在 2 之前弹出。
81+
82+
**提示:**
83+
84+
- `1 <= pushed.length <= 1000`
85+
- `0 <= pushed[i] <= 1000`
86+
- `pushed` 的所有元素 **互不相同**
87+
- `popped.length == pushed.length`
88+
- `popped``pushed` 的一个排列
6089

6190
## 解题思路
6291

63-
这道题可以使用模拟栈的方法进行判断,使用一个辅助栈 `stack`,模拟 `push``pop` 操作,最后通过判断栈是否为空来得到最终的结果。
92+
这道题可以使用模拟栈的方法进行判断,使用一个辅助栈 `stack`,模拟 入栈(`push`)和出栈(`pop`)操作,最后通过判断栈是否为空来来验证序列的正确性。
93+
94+
1. **初始化:**
6495

65-
具体思路如下:
96+
- 创建一个空栈 `stack` 来模拟栈的操作。
97+
- 设置一个变量 `popIndex` 为 0,表示当前需要匹配的出栈序列中的元素位置。
6698

67-
1. 遍历 `pushed` 数组,模拟入栈操作,并在每次入栈后,判断是否需要执行出栈操作。
68-
2. 如果当前栈顶元素等于 `popped` 数组中下一个要出栈的元素,则执行出栈操作。
69-
3. 遍历结束后,判断栈是否为空。
99+
2. **遍历 `pushed`**
100+
101+
- 将每个元素 `item` 入栈(`stack.push(item)`)。
102+
- 在每次入栈后,检查栈顶元素是否与 `popped[popIndex]` 相等:
103+
- 如果相等,说明当前出栈序列中的元素可以出栈,我们执行 `stack.pop()` 并将 `popIndex` 加 1。
104+
- 继续重复这个过程,直到栈顶元素与 `popped[popIndex]` 不相等或栈为空。
105+
106+
3. **验证结果:**
107+
- 如果最终栈为空,说明 `popped` 是合法的出栈序列;否则不是。
108+
109+
#### 复杂度分析
110+
111+
- **时间复杂度**`O(n)`,其中 `n``pushed` 的长度,每个元素入栈一次,最多出栈一次,总操作次数是 `O(n)`
112+
- **空间复杂度**`O(n)`,栈最多存储 `pushed` 中的所有元素。
70113

71114
## 代码
72115

73116
```javascript
74-
117+
/**
118+
* @param {number[]} pushed
119+
* @param {number[]} popped
120+
* @return {boolean}
121+
*/
122+
var validateStackSequences = function (pushed, popped) {
123+
let stack = []; // 模拟栈操作
124+
let popIndex = 0; // 指向出栈序列的当前位置
125+
126+
for (let item of pushed) {
127+
stack.push(item); // 入栈操作
128+
// 栈顶元素与当前出栈元素相等时,执行出栈操作
129+
while (stack.length > 0 && stack[stack.length - 1] === popped[popIndex]) {
130+
stack.pop();
131+
popIndex++;
132+
}
133+
}
134+
135+
// 如果栈为空,表示出栈序列是合法的
136+
return stack.length === 0;
137+
};
75138
```

0 commit comments

Comments
 (0)