File tree Expand file tree Collapse file tree 12 files changed +197
-13
lines changed
src/main/java/com/diguage Expand file tree Collapse file tree 12 files changed +197
-13
lines changed Original file line number Diff line number Diff line change @@ -285,12 +285,12 @@ TIP: **公众号的微信号是: `jikerizhi`**。__因为众所周知的原因
285
285
|Medium
286
286
|
287
287
288
- // |{counter:codes}
289
- // |{leetcode_base_url}/sudoku-solver/[37. Sudoku Solver^]
290
- // |{source_base_url}/_0037_SudokuSolver.java[Java]
291
- // |{doc_base_url}/0037-sudoku-solver.adoc[题解]
292
- // |Hard
293
- // |
288
+ |{counter:codes}
289
+ |{leetcode_base_url}/sudoku-solver/[37. Sudoku Solver^]
290
+ |{source_base_url}/_0037_SudokuSolver.java[Java]
291
+ |{doc_base_url}/0037-sudoku-solver.adoc[题解]
292
+ |Hard
293
+ |
294
294
295
295
|{counter:codes}
296
296
|{leetcode_base_url}/count-and-say/[38. Count and Say^]
Original file line number Diff line number Diff line change 7
7
8
8
回溯优化,重要的是,要学会剪枝!
9
9
10
+ 回溯三部曲:
11
+
12
+ . 定义递归函数以及参数
13
+ . 确定递归终止条件
14
+ . 思考递归单层搜索逻辑
15
+
16
+ == 经典题目
17
+
18
+ image::images/backtrack-01.png[{image_attr}]
19
+
20
+ . xref:0077-combinations.adoc[77. Combinations]
21
+ . xref:0216-combination-sum-iii.adoc[216. Combination Sum III]
22
+ . xref:0017-letter-combinations-of-a-phone-number.adoc[17. Letter Combinations of a Phone Number]
23
+ . xref:0039-combination-sum.adoc[39. Combination Sum]
24
+ . xref:0040-combination-sum-ii.adoc[40. Combination Sum II]
25
+ . xref:0131-palindrome-partitioning.adoc[131. Palindrome Partitioning]
26
+ . xref:0093-restore-ip-addresses.adoc[93. Restore IP Addresses]
27
+ . xref:0078-subsets.adoc[78. Subsets]
28
+ . xref:0090-subsets-ii.adoc[90. Subsets II]
29
+ . xref:0491-increasing-subsequences.adoc[491. Increasing Subsequences]
30
+ . xref:0046-permutations.adoc[46. Permutations]
31
+ . xref:0047-permutations-ii.adoc[47. Permutations II]
32
+ . xref:0332-reconstruct-itinerary.adoc[332. Reconstruct Itinerary]
33
+ . xref:0051-n-queens.adoc[51. N-Queens]
34
+ . xref:0052-n-queens-ii.adoc[52. N-Queens II]
35
+ . xref:0037-sudoku-solver.adoc[37. Sudoku Solver]
36
+
37
+
10
38
== 附加题
11
39
12
40
. 写程序尝试生成递归调用树。
Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ A sudoku solution must satisfy *all of the following rules*:
15
15
16
16
Empty cells are indicated by the character `'.'` .
17
17
18
- image::images/0037-1 .png[{image_attr}]
18
+ image::images/0037-01 .png[{image_attr}]
19
19
20
20
[.small]#A sudoku puzzle...#
21
21
22
- image::images/0037-2 .png[{image_attr}]
22
+ image::images/0037-02 .png[{image_attr}]
23
23
24
24
[.small]#...and its solution numbers marked in red.#
25
25
@@ -33,13 +33,34 @@ image::images/0037-2.png[{image_attr}]
33
33
34
34
这道题特别需要关注的点是:只要找到一个解就可以了,不需要求全部解。所以,需要重点思考的是,如何在找到第一个解时,就立即停止搜索。
35
35
36
+ 递归树
37
+
38
+ image::images/0037-03.png[{image_attr}]
39
+
36
40
[[src-0037]]
41
+ [tabs]
42
+ ====
43
+ 一刷::
44
+ +
45
+ --
37
46
[{java_src_attr}]
38
47
----
39
48
include::{sourcedir}/_0037_SudokuSolver.java[tag=answer]
40
49
----
50
+ --
51
+
52
+ 二刷::
53
+ +
54
+ --
55
+ [{java_src_attr}]
56
+ ----
57
+ include::{sourcedir}/_0037_SudokuSolver_2.java[tag=answer]
58
+ ----
59
+ --
60
+ ====
41
61
42
62
== 参考资料
43
63
44
64
. https://mp.weixin.qq.com/s/VCirGskFGPln-S2LGFTgKg[搞懂回溯算法,我终于能做数独了^]
65
+ . https://leetcode.cn/problems/sudoku-solver/solutions/414261/37-jie-shu-du-hui-su-sou-suo-suan-fa-xiang-jie-by-/[37. 解数独 - 「代码随想录」带你学透回溯算法!^]
45
66
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 444
444
|{doc_base_url} /0416-partition-equal-subset-sum.adoc[题解]
445
445
|动态规划,0/1背包问题
446
446
447
+ |{counter:codes}
448
+ |{leetcode_base_url} /sudoku-solver/[37. Sudoku Solver^]
449
+ |{doc_base_url} /0037-sudoku-solver.adoc[题解]
450
+ |回溯
451
+
447
452
448
453
|===
449
454
Original file line number Diff line number Diff line change 12
12
*/
13
13
public class _0037_SudokuSolver {
14
14
// tag::answer[]
15
+ /**
16
+ * * @author D瓜哥 · https://www.diguage.com
17
+ * * @since 2020-03-25 09:34
18
+ */
15
19
public void solveSudoku (char [][] board ) {
16
20
backtrack (board , 0 );
17
21
}
You can’t perform that action at this time.
0 commit comments