更新 图论 并查集 模拟 位运算 额外题目 排版格式修复

This commit is contained in:
jinbudaily
2023-07-27 14:48:04 +08:00
parent e9b0d46f35
commit a5eb340ee6
7 changed files with 51 additions and 44 deletions

View File

@ -34,7 +34,7 @@
* 输出:[1]
# 思路
## 思路
一些同学可能手动写排列的顺序都没有写对那么写程序的话思路一定是有问题的了我这里以1234为例子把全排列都列出来。可以参考一下规律所在
@ -92,9 +92,9 @@ public:
};
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
@ -159,7 +159,7 @@ class Solution {
}
```
## Python
### Python
>直接使用sorted()会开辟新的空间并返回一个新的list故补充一个原地反转函数
```python
class Solution:
@ -191,7 +191,7 @@ class Solution:
"""
```
## Go
### Go
```go
//卡尔的解法
@ -216,7 +216,7 @@ func reverse(a []int,begin,end int){
}
```
## JavaScript
### JavaScript
```js
//卡尔的解法(吐槽一下JavaScript的sort和其他语言的不太一样只想到了拷贝数组去排序再替换原数组来实现nums的[i + 1, nums.length)升序排序)
@ -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>

View File

@ -29,7 +29,7 @@
* 解释endWord "cog" 不在字典中,所以无法进行转换。
# 思路
## 思路
以示例1为例从这个图中可以看出 hit 到 cog的路线不止一条有三条一条是最短的长度为5两条长度为6。
@ -97,9 +97,9 @@ public:
当然本题也可以用双向BFS就是从头尾两端进行搜索大家感兴趣可以自己去实现这里就不再做详细讲解了。
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
public int ladderLength(String beginWord, String endWord, List<String> wordList) {
@ -196,7 +196,7 @@ class Solution {
}
```
## Python
### Python
```
class Solution:
@ -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
@ -274,7 +274,7 @@ func getCandidates(word string) []string {
}
```
## JavaScript
### JavaScript
```javascript
var ladderLength = function(beginWord, endWord, wordList) {
// 将wordList转成Set提高查询速度
@ -310,7 +310,7 @@ var ladderLength = function(beginWord, endWord, wordList) {
};
```
## TypeScript
### TypeScript
```typescript
function ladderLength(
beginWord: string,
@ -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>

View File

@ -90,7 +90,7 @@ public:
## 其他语言版本
Java
### Java
```java
// 解法一
@ -191,8 +191,8 @@ class Solution {
```
Python
### 解法1:
### Python
扫描每个cell,如果当前位置为岛屿 grid[i][j] == 1 从当前位置判断四边方向如果边界或者是水域证明有边界存在res矩阵的对应cell加一。
```python
@ -228,7 +228,8 @@ class Solution:
```
Go
### Go
```go
func islandPerimeter(grid [][]int) int {
m, n := len(grid), len(grid[0])
@ -249,7 +250,8 @@ func islandPerimeter(grid [][]int) int {
}
```
JavaScript
### JavaScript
```javascript
//解法一
var islandPerimeter = function(grid) {
@ -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>

View File

@ -29,7 +29,7 @@
# 思路
## 思路
这道题目还是挺简单的,大家不要想复杂了,一波哈希法又一波图论算法啥的,哈哈。
@ -64,9 +64,9 @@ public:
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
// 时间复杂度O(n)
@ -86,7 +86,7 @@ class Solution {
}
```
## Python
### Python
```python
# 时间复杂度O(n)
@ -107,7 +107,7 @@ class Solution:
return x == 0 and y == 0
```
## Go
### Go
```go
func judgeCircle(moves string) bool {
@ -131,7 +131,7 @@ func judgeCircle(moves string) bool {
}
```
## JavaScript
### JavaScript
```js
// 时间复杂度O(n)
@ -150,7 +150,7 @@ var judgeCircle = function(moves) {
```
## TypeScript
### TypeScript
```ts
var judgeCircle = function (moves) {
@ -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>

View File

@ -25,7 +25,7 @@
* edges 中无重复元素
* 给定的图是连通的 
# 思路
## 思路
这道题目也是并查集基础题目
@ -150,9 +150,9 @@ public:
可以看出主函数的代码很少就判断一下边的两个节点在不在同一个集合就可以了
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
@ -205,7 +205,7 @@ class Solution {
}
```
## Python
### Python
```python
@ -256,7 +256,7 @@ class Solution:
return []
```
## Go
### Go
```go
@ -312,7 +312,7 @@ func findRedundantConnection(edges [][]int) []int {
}
```
## JavaScript
### JavaScript
```js
const n = 1005;
@ -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>

View File

@ -213,9 +213,9 @@ public:
```
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
@ -335,7 +335,7 @@ class Solution {
}
```
## Python
### Python
```python
@ -426,7 +426,7 @@ class Solution:
return self.getRemoveEdge(edges)
```
## Go
### Go
```go
@ -527,7 +527,7 @@ func findRedundantDirectedConnection(edges [][]int) []int {
```
## JavaScript
### JavaScript
```js
const N = 1010; // 如题二维数组大小的在3到1000范围内
@ -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>

View File

@ -46,7 +46,7 @@
# 思路
## 思路
这道题其实是考察如何计算一个数的二进制中1的数量。
@ -87,7 +87,7 @@ int bitCount(int n) {
下面我就使用方法二,来做这道题目:
## C++代码
```C++
class Solution {
@ -116,9 +116,9 @@ public:
# 其他语言版本
## 其他语言版本
## Java
### Java
```java
class Solution {
@ -151,7 +151,7 @@ class Solution {
## Python
### Python
```python
class Solution:
@ -167,7 +167,7 @@ class Solution:
return count
```
## Go
### Go
```go
func sortByBits(arr []int) []int {
@ -205,7 +205,7 @@ func bitCount(n int) int {
}
```
## JavaScript
### JavaScript
```js
var sortByBits = function(arr) {
@ -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>