Skip to content

Commit

Permalink
更新 图论 并查集 模拟 位运算 额外题目 排版格式修复
Browse files Browse the repository at this point in the history
  • Loading branch information
jinbudaily committed Jul 27, 2023
1 parent e9b0d46 commit a5eb340
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 44 deletions.
13 changes: 7 additions & 6 deletions problems/0031.下一个排列.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* 输出:[1]


# 思路
## 思路

一些同学可能手动写排列的顺序,都没有写对,那么写程序的话思路一定是有问题的了,我这里以1234为例子,把全排列都列出来。可以参考一下规律所在:

Expand Down Expand Up @@ -92,9 +92,9 @@ public:
};
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
Expand Down Expand Up @@ -159,7 +159,7 @@ class Solution {
}
```
## Python
### Python
>直接使用sorted()会开辟新的空间并返回一个新的list,故补充一个原地反转函数
```python
class Solution:
Expand Down Expand Up @@ -191,7 +191,7 @@ class Solution:
"""
```

## Go
### Go

```go
//卡尔的解法
Expand All @@ -216,7 +216,7 @@ func reverse(a []int,begin,end int){
}
```

## JavaScript
### JavaScript

```js
//卡尔的解法(吐槽一下JavaScript的sort和其他语言的不太一样,只想到了拷贝数组去排序再替换原数组来实现nums的[i + 1, nums.length)升序排序)
Expand Down Expand Up @@ -272,3 +272,4 @@ var nextPermutation = function(nums) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

15 changes: 7 additions & 8 deletions problems/0127.单词接龙.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* 解释:endWord "cog" 不在字典中,所以无法进行转换。


# 思路
## 思路

以示例1为例,从这个图中可以看出 hit 到 cog的路线,不止一条,有三条,一条是最短的长度为5,两条长度为6。

Expand Down Expand Up @@ -97,9 +97,9 @@ public:

当然本题也可以用双向BFS,就是从头尾两端进行搜索,大家感兴趣,可以自己去实现,这里就不再做详细讲解了。

# 其他语言版本
## 其他语言版本

## Java
### Java

```java
public int ladderLength(String beginWord, String endWord, List<String> wordList) {
Expand Down Expand Up @@ -196,7 +196,7 @@ class Solution {
}
```

## Python
### Python

```
class Solution:
Expand All @@ -221,7 +221,7 @@ class Solution:
queue.append(newWord)
return 0
```
## Go
### Go
```go
func ladderLength(beginWord string, endWord string, wordList []string) int {
wordMap, que, depth := getWordMap(wordList, beginWord), []string{beginWord}, 0
Expand Down Expand Up @@ -274,7 +274,7 @@ func getCandidates(word string) []string {
}
```

## JavaScript
### JavaScript
```javascript
var ladderLength = function(beginWord, endWord, wordList) {
// 将wordList转成Set,提高查询速度
Expand Down Expand Up @@ -310,7 +310,7 @@ var ladderLength = function(beginWord, endWord, wordList) {
};
```

## TypeScript
### TypeScript
```typescript
function ladderLength(
beginWord: string,
Expand Down Expand Up @@ -364,4 +364,3 @@ function diffonechar(word1: string, word2: string): boolean {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

13 changes: 8 additions & 5 deletions problems/0463.岛屿的周长.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public:

## 其他语言版本

Java:
### Java:

```java
// 解法一
Expand Down Expand Up @@ -191,8 +191,8 @@ class Solution {

```

Python:
### 解法1:
### Python:

扫描每个cell,如果当前位置为岛屿 grid[i][j] == 1, 从当前位置判断四边方向,如果边界或者是水域,证明有边界存在,res矩阵的对应cell加一。

```python
Expand Down Expand Up @@ -228,7 +228,8 @@ class Solution:

```

Go:
### Go:

```go
func islandPerimeter(grid [][]int) int {
m, n := len(grid), len(grid[0])
Expand All @@ -249,7 +250,8 @@ func islandPerimeter(grid [][]int) int {
}
```

JavaScript:
### JavaScript:

```javascript
//解法一
var islandPerimeter = function(grid) {
Expand Down Expand Up @@ -305,3 +307,4 @@ var islandPerimeter = function(grid) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

15 changes: 8 additions & 7 deletions problems/0657.机器人能否返回原点.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@



# 思路
## 思路

这道题目还是挺简单的,大家不要想复杂了,一波哈希法又一波图论算法啥的,哈哈。

Expand Down Expand Up @@ -64,9 +64,9 @@ public:
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
// 时间复杂度:O(n)
Expand All @@ -86,7 +86,7 @@ class Solution {
}
```

## Python
### Python

```python
# 时间复杂度:O(n)
Expand All @@ -107,7 +107,7 @@ class Solution:
return x == 0 and y == 0
```

## Go
### Go

```go
func judgeCircle(moves string) bool {
Expand All @@ -131,7 +131,7 @@ func judgeCircle(moves string) bool {
}
```

## JavaScript
### JavaScript

```js
// 时间复杂度:O(n)
Expand All @@ -150,7 +150,7 @@ var judgeCircle = function(moves) {
```


## TypeScript
### TypeScript

```ts
var judgeCircle = function (moves) {
Expand Down Expand Up @@ -185,3 +185,4 @@ var judgeCircle = function (moves) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

13 changes: 7 additions & 6 deletions problems/0684.冗余连接.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* edges 中无重复元素
* 给定的图是连通的 

# 思路
## 思路

这道题目也是并查集基础题目。

Expand Down Expand Up @@ -150,9 +150,9 @@ public:
可以看出,主函数的代码很少,就判断一下边的两个节点在不在同一个集合就可以了。


# 其他语言版本
## 其他语言版本

## Java
### Java

```java
class Solution {
Expand Down Expand Up @@ -205,7 +205,7 @@ class Solution {
}
```

## Python
### Python

```python

Expand Down Expand Up @@ -256,7 +256,7 @@ class Solution:
return []
```

## Go
### Go

```go

Expand Down Expand Up @@ -312,7 +312,7 @@ func findRedundantConnection(edges [][]int) []int {
}
```

## JavaScript
### JavaScript

```js
const n = 1005;
Expand Down Expand Up @@ -365,3 +365,4 @@ var findRedundantConnection = function(edges) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

11 changes: 6 additions & 5 deletions problems/0685.冗余连接II.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public:
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
Expand Down Expand Up @@ -335,7 +335,7 @@ class Solution {
}
```

## Python
### Python

```python

Expand Down Expand Up @@ -426,7 +426,7 @@ class Solution:
return self.getRemoveEdge(edges)
```

## Go
### Go

```go

Expand Down Expand Up @@ -527,7 +527,7 @@ func findRedundantDirectedConnection(edges [][]int) []int {

```

## JavaScript
### JavaScript

```js
const N = 1010; // 如题:二维数组大小的在3到1000范围内
Expand Down Expand Up @@ -623,3 +623,4 @@ var findRedundantDirectedConnection = function(edges) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

15 changes: 8 additions & 7 deletions problems/1356.根据数字二进制下1的数目排序.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@



# 思路
## 思路

这道题其实是考察如何计算一个数的二进制中1的数量。

Expand Down Expand Up @@ -87,7 +87,7 @@ int bitCount(int n) {

下面我就使用方法二,来做这道题目:

## C++代码


```C++
class Solution {
Expand Down Expand Up @@ -116,9 +116,9 @@ public:
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
Expand Down Expand Up @@ -151,7 +151,7 @@ class Solution {



## Python
### Python

```python
class Solution:
Expand All @@ -167,7 +167,7 @@ class Solution:
return count
```

## Go
### Go

```go
func sortByBits(arr []int) []int {
Expand Down Expand Up @@ -205,7 +205,7 @@ func bitCount(n int) int {
}
```

## JavaScript
### JavaScript

```js
var sortByBits = function(arr) {
Expand All @@ -227,3 +227,4 @@ var sortByBits = function(arr) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

0 comments on commit a5eb340

Please sign in to comment.