Skip to content

Commit b1443f9

Browse files
author
liwentian
committed
fd
1 parent bb50be2 commit b1443f9

File tree

5 files changed

+8
-34
lines changed

5 files changed

+8
-34
lines changed

ebook/tree/Tree.tex

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,9 +1292,9 @@ \subsubsection{Solution I}
12921292

12931293
\begin{Code}
12941294
/**
1295-
* 当root.val == Sum时,不要return,因为继续往下走可能有路径刚好加起来为0,典型的为[1,-2,1,-1],目标和为-1
1296-
* 这里隐藏了四条路径,[1,-2], [-2,1], [-1], [1,-2,1,-1],如果在[1,-2]就return了,那就会掉了[1,-2,1,-1]
1297-
* 可参考https://discuss.leetcode.com/category/562/path-sum-iii
1295+
* 当root.val == Sum时,不要return,因为继续往下走可能有路径刚好加起来为0,典型的为[1,-2,1,-1],
1296+
* 目标和为-1, 这里隐藏了四条路径,[1,-2], [-2,1], [-1], [1,-2,1,-1],如果在[1,-2]就return了,
1297+
* 那就会掉了[1,-2,1,-1]
12981298
*/
12991299

13001300
/**
@@ -1857,6 +1857,7 @@ \subsubsection{Solution}
18571857
return rob(root, true);
18581858
}
18591859

1860+
// rob true表示不定,false表示不选root
18601861
private int rob(TreeNode root, boolean rob) {
18611862
if (root == null) {
18621863
return 0;
@@ -2004,18 +2005,6 @@ \subsubsection{Description}
20042005
\subsubsection{Solution}
20052006

20062007
\begin{Code}
2007-
/**
2008-
* 错误的写法,和第104题非常类似
2009-
public int minDepth(TreeNode root) {
2010-
if (root == null) {
2011-
return 0;
2012-
}
2013-
if (root.left == null && root.right == null) {
2014-
return 1;
2015-
}
2016-
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
2017-
}*/
2018-
20192008
public int minDepth(TreeNode root) {
20202009
if (root == null) {
20212010
return 0;
@@ -2029,24 +2018,6 @@ \subsubsection{Solution}
20292018
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
20302019
}
20312020
}
2032-
2033-
/**
2034-
public int minDepth(TreeNode root) {
2035-
if (root == null) {
2036-
return 0;
2037-
}
2038-
return helper(root);
2039-
}
2040-
2041-
private int helper(TreeNode root) {
2042-
if (root == null) {
2043-
return Integer.MAX_VALUE;
2044-
}
2045-
if (root.left == null && root.right == null) {
2046-
return 1;
2047-
}
2048-
return Math.min(helper(root.left), helper(root.right)) + 1;
2049-
}*/
20502021
\end{Code}
20512022

20522023
\newpage

ebook/tree/leetcode-tree.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is XeTeX, Version 3.14159265-2.6-0.99996 (TeX Live 2016) (preloaded format=xelatex 2017.9.4) 22 SEP 2017 10:48
1+
This is XeTeX, Version 3.14159265-2.6-0.99996 (TeX Live 2016) (preloaded format=xelatex 2017.9.4) 23 SEP 2017 18:04
22
entering extended mode
33
restricted \write18 enabled.
44
%&-line parsing enabled.

ebook/tree/leetcode-tree.pdf

-81 Bytes
Binary file not shown.
-586 Bytes
Binary file not shown.

solution/src/main/java/com/inuker/solution/HouseRobberIII.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public int rob(TreeNode root) {
1212
return rob(root, true);
1313
}
1414

15+
/**
16+
* @param rob true表示不定,false表示不选root
17+
*/
1518
private int rob(TreeNode root, boolean rob) {
1619
if (root == null) {
1720
return 0;

0 commit comments

Comments
 (0)