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

Sign up
Appearance settings

Commit 59ec9b5

Browse files
Merge branch 'master' of github.com:jinbudaily/leetcode-master
2 parents 10b693a + d0f7d46 commit 59ec9b5

File tree

54 files changed

+331
-98
lines changed

Some content is hidden

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

54 files changed

+331
-98
lines changed

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,14 @@
393393
* [图论:1020.飞地的数量](./problems/1020.飞地的数量.md)
394394
* [图论:130.被围绕的区域](./problems/0130.被围绕的区域.md)
395395
* [图论:417.太平洋大西洋水流问题](./problems/0417.太平洋大西洋水流问题.md)
396+
* [图论:827.最大人工岛](./problems/0827.最大人工岛.md)
397+
* [图论:127. 单词接龙](./problems/0127.单词接龙.md)
398+
* [图论:841.钥匙和房间](./problems/841.钥匙和房间)
399+
* [图论:463. 岛屿的周长](./problems/0463.岛屿的周长.md)
400+
* [图论:并查集理论基础](./problems/)
401+
* [图论:1971. 寻找图中是否存在路径](./problems/1971.寻找图中是否存在路径.md)
402+
* [图论:684.冗余连接](./problems/0684.冗余连接.md)
403+
* [图论:685.冗余连接II](./problems/0685.冗余连接II.md)
396404

397405
(持续更新中....)
398406

‎problems/0059.螺旋矩阵II.md‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ class Solution:
211211

212212
```javascript
213213

214-
/**
215-
* @param {number} n
216-
* @return {number[][]}
217-
*/
218214
var generateMatrix = function(n) {
219215
let startX = startY = 0; // 起始位置
220216
let loop = Math.floor(n/2); // 旋转圈数
@@ -226,11 +222,11 @@ var generateMatrix = function(n) {
226222
while (loop--) {
227223
let row = startX, col = startY;
228224
// 上行从左到右(左闭右开)
229-
for (; col < startY +n - offset; col++) {
225+
for (; col < n - offset; col++) {
230226
res[row][col] = count++;
231227
}
232228
// 右列从上到下(左闭右开)
233-
for (; row < startX +n - offset; row++) {
229+
for (; row < n - offset; row++) {
234230
res[row][col] = count++;
235231
}
236232
// 下行从右到左(左闭右开)
@@ -247,14 +243,15 @@ var generateMatrix = function(n) {
247243
startY++;
248244

249245
// 更新offset
250-
offset += 2;
246+
offset += 1;
251247
}
252248
// 如果n为奇数的话,需要单独给矩阵最中间的位置赋值
253249
if (n % 2 === 1) {
254250
res[mid][mid] = count;
255251
}
256252
return res;
257253
};
254+
258255

259256

260257
```

‎problems/0096.不同的二叉搜索树.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public:
159159
160160
可以看出我依然还是用动规五部曲来进行分析,会把题目的方方面面都覆盖到!
161161
162-
**而且具体这五部分析是我自己平时总结的经验,找不出来第二个的,可能过一阵子 其他题解也会有动规五部曲了,哈哈**。
162+
**而且具体这五部分析是我自己平时总结的经验,找不出来第二个的,可能过一阵子 其他题解也会有动规五部曲了**。
163163
164164
当时我在用动规五部曲讲解斐波那契的时候,一些录友和我反应,感觉讲复杂了。
165165

‎problems/0098.验证二叉搜索树.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ public:
249249

250250
这道题目是一个简单题,但对于没接触过的同学还是有难度的。
251251

252-
所以初学者刚开始学习算法的时候,看到简单题目没有思路很正常,千万别怀疑自己智商,学习过程都是这样的,大家智商都差不多,哈哈
252+
所以初学者刚开始学习算法的时候,看到简单题目没有思路很正常,千万别怀疑自己智商,学习过程都是这样的,大家智商都差不多。
253253

254-
只要把基本类型的题目都做过,总结过之后,思路自然就开阔了
254+
只要把基本类型的题目都做过,总结过之后,思路自然就开阔了,加油💪
255255

256256

257257
## 其他语言版本

‎problems/0131.分割回文串.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public:
300300

301301
所以本题应该是一道hard题目了。
302302

303-
**可能刷过这道题目的录友都没感受到自己原来克服了这么多难点,就把这道题目AC了**,这应该叫做无招胜有招,人码合一,哈哈哈
303+
**可能刷过这道题目的录友都没感受到自己原来克服了这么多难点,就把这道题目AC了**,这应该叫做无招胜有招,人码合一。
304304

305305

306306

‎problems/0142.环形链表II.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public:
187187
188188
## 总结
189189
190-
这次可以说把环形链表这道题目的各个细节,完完整整的证明了一遍,说这是全网最详细讲解不为过吧,哈哈
190+
这次可以说把环形链表这道题目的各个细节,完完整整的证明了一遍,说这是全网最详细讲解不为过吧。
191191
192192
193193
## 其他语言版本

‎problems/0200.岛屿数量.广搜版.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,47 @@ class Solution:
240240

241241
```
242242

243+
### Rust
244+
245+
```rust
246+
247+
use std::collections::VecDeque;
248+
impl Solution {
249+
const DIRECTIONS: [(i32, i32); 4] = [(0, 1), (1, 0), (-1, 0), (0, -1)];
250+
pub fn num_islands(grid: Vec<Vec<char>>) -> i32 {
251+
let mut visited = vec![vec![false; grid[0].len()]; grid.len()];
252+
let mut res = 0;
253+
for (i, chars) in grid.iter().enumerate() {
254+
for (j, &c) in chars.iter().enumerate() {
255+
if !visited[i][j] && c == '1' {
256+
res += 1;
257+
Self::bfs(&grid, &mut visited, (i as i32, j as i32));
258+
}
259+
}
260+
}
261+
res
262+
}
263+
264+
pub fn bfs(grid: &Vec<Vec<char>>, visited: &mut Vec<Vec<bool>>, (x, y): (i32, i32)) {
265+
let mut queue = VecDeque::new();
266+
queue.push_back((x, y));
267+
visited[x as usize][y as usize] = true;
268+
while let Some((cur_x, cur_y)) = queue.pop_front() {
269+
for (dx, dy) in Self::DIRECTIONS {
270+
let (nx, ny) = (cur_x + dx, cur_y + dy);
271+
if nx < 0 || nx >= grid.len() as i32 || ny < 0 || ny >= grid[0].len() as i32 {
272+
continue;
273+
}
274+
let (nx, ny) = (nx as usize, ny as usize);
275+
if grid[nx][ny] == '1' && !visited[nx][ny] {
276+
visited[nx][ny] = true;
277+
queue.push_back((nx as i32, ny as i32));
278+
}
279+
}
280+
}
281+
}
282+
}
283+
```
243284
<p align="center">
244285
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
245286
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

‎problems/0200.岛屿数量.深搜版.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,42 @@ class Solution:
279279
return result
280280
```
281281

282+
Rust:
283+
284+
285+
```rust
286+
impl Solution {
287+
const DIRECTIONS: [(i32, i32); 4] = [(0, 1), (1, 0), (-1, 0), (0, -1)];
288+
pub fn num_islands(grid: Vec<Vec<char>>) -> i32 {
289+
let mut visited = vec![vec![false; grid[0].len()]; grid.len()];
290+
let mut res = 0;
291+
for (i, chars) in grid.iter().enumerate() {
292+
for (j, &c) in chars.iter().enumerate() {
293+
if !visited[i][j] && c == '1' {
294+
res += 1;
295+
Self::dfs(&grid, &mut visited, (i as i32, j as i32));
296+
}
297+
}
298+
}
299+
res
300+
}
301+
302+
pub fn dfs(grid: &Vec<Vec<char>>, visited: &mut Vec<Vec<bool>>, (x, y): (i32, i32)) {
303+
for (dx, dy) in Self::DIRECTIONS {
304+
let (nx, ny) = (x + dx, y + dy);
305+
if nx < 0 || nx >= grid.len() as i32 || ny < 0 || ny >= grid[0].len() as i32 {
306+
continue;
307+
}
308+
let (nx, ny) = (nx as usize, ny as usize);
309+
if grid[nx][ny] == '1' && !visited[nx][ny] {
310+
visited[nx][ny] = true;
311+
Self::dfs(grid, visited, (nx as i32, ny as i32));
312+
}
313+
}
314+
}
315+
}
316+
```
317+
282318
<p align="center">
283319
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
284320
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

‎problems/0225.用队列实现栈.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public:
111111
}
112112
};
113113
```
114-
* 时间复杂度: push为O(n),其他为O(1)
114+
* 时间复杂度: pop为O(n),其他为O(1)
115115
* 空间复杂度: O(n)
116116
117117
## 优化
@@ -158,7 +158,7 @@ public:
158158
}
159159
};
160160
```
161-
* 时间复杂度: push为O(n),其他为O(1)
161+
* 时间复杂度: pop为O(n),其他为O(1)
162162
* 空间复杂度: O(n)
163163

164164

‎problems/0232.用栈实现队列.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public:
127127
128128
工作中如果发现某一个功能自己要经常用,同事们可能也会用到,自己就花点时间把这个功能抽象成一个好用的函数或者工具类,不仅自己方便,也方便了同事们。
129129
130-
同事们就会逐渐认可你的工作态度和工作能力,自己的口碑都是这么一点一点积累起来的!在同事圈里口碑起来了之后,你就发现自己走上了一个正循环,以后的升职加薪才少不了你!哈哈哈
130+
同事们就会逐渐认可你的工作态度和工作能力,自己的口碑都是这么一点一点积累起来的!在同事圈里口碑起来了之后,你就发现自己走上了一个正循环,以后的升职加薪才少不了你!
131131
132132
133133

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /