Update
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
如果对回溯法理论还不清楚的同学,可以先看这个视频[视频来了!!带你学透回溯算法(理论篇)](https://mp.weixin.qq.com/s/wDd5azGIYWjbU0fdua_qBg)
|
||||
|
||||
## 37. 解数独
|
||||
# 37. 解数独
|
||||
|
||||
[力扣题目链接](https://leetcode-cn.com/problems/sudoku-solver/)
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||

|
||||
|
||||
|
||||
## 回溯三部曲
|
||||
### 回溯三部曲
|
||||
|
||||
* 递归函数以及参数
|
||||
|
||||
@@ -115,7 +115,7 @@ bool backtracking(vector<vector<char>>& board) {
|
||||
|
||||
那么会直接返回, **这也就是为什么没有终止条件也不会永远填不满棋盘而无限递归下去!**
|
||||
|
||||
## 判断棋盘是否合法
|
||||
### 判断棋盘是否合法
|
||||
|
||||
判断棋盘是否合法有如下三个维度:
|
||||
|
||||
@@ -150,9 +150,8 @@ bool isValid(int row, int col, char val, vector<vector<char>>& board) {
|
||||
}
|
||||
```
|
||||
|
||||
最后整体代码如下:
|
||||
最后整体C++代码如下:
|
||||
|
||||
## C++代码
|
||||
|
||||
```CPP
|
||||
class Solution {
|
||||
@@ -218,7 +217,7 @@ public:
|
||||
## 其他语言版本
|
||||
|
||||
|
||||
Java:
|
||||
### Java
|
||||
```java
|
||||
class Solution {
|
||||
public void solveSudoku(char[][] board) {
|
||||
@@ -286,7 +285,7 @@ class Solution {
|
||||
}
|
||||
```
|
||||
|
||||
Python:
|
||||
### Python
|
||||
```python3
|
||||
class Solution:
|
||||
def solveSudoku(self, board: List[List[str]]) -> None:
|
||||
@@ -321,7 +320,7 @@ class Solution:
|
||||
backtrack(board)
|
||||
```
|
||||
|
||||
Python3:
|
||||
### Python3
|
||||
|
||||
```python3
|
||||
class Solution:
|
||||
@@ -374,7 +373,7 @@ class Solution:
|
||||
self.isSolved()
|
||||
```
|
||||
|
||||
Go:
|
||||
### Go
|
||||
|
||||
```go
|
||||
func solveSudoku(board [][]byte) {
|
||||
@@ -431,7 +430,7 @@ func isvalid(row,col int,k byte,board [][]byte)bool{
|
||||
|
||||
|
||||
|
||||
Javascript:
|
||||
### Javascript
|
||||
```Javascript
|
||||
var solveSudoku = function(board) {
|
||||
function isValid(row, col, val, board) {
|
||||
@@ -487,7 +486,7 @@ var solveSudoku = function(board) {
|
||||
};
|
||||
```
|
||||
|
||||
C:
|
||||
### C
|
||||
|
||||
```C
|
||||
bool isValid(char** board, int row, int col, int k) {
|
||||
|
||||
Reference in New Issue
Block a user