Skip to content

Commit 5ad95ff

Browse files
refactor 337
1 parent b8610a4 commit 5ad95ff

File tree

1 file changed

+1
-28
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+1
-28
lines changed

src/main/java/com/fishercoder/solutions/_337.java

+1-28
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,6 @@
55
import java.util.HashMap;
66
import java.util.Map;
77

8-
/**337. House Robber III
9-
10-
The thief has found himself a new place for his thievery again.
11-
There is only one entrance to this area, called the "root."
12-
Besides the root, each house has one and only one parent house.
13-
After a tour, the smart thief realized that "all houses in this place forms a binary tree".
14-
It will automatically contact the police if two directly-linked houses were broken into on the same night.
15-
16-
Determine the maximum amount of money the thief can rob tonight without alerting the police.
17-
18-
Example 1:
19-
3
20-
/ \
21-
2 3
22-
\ \
23-
3 1
24-
Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.
25-
26-
Example 2:
27-
3
28-
/ \
29-
4 5
30-
/ \ \
31-
1 3 1
32-
Maximum amount of money the thief can rob = 4 + 5 = 9.
33-
*/
34-
358
public class _337 {
369

3710
public static class Solution1 {
@@ -76,7 +49,7 @@ private int getMaxValue(TreeNode root, Map<TreeNode, Integer> map) {
7649
val += getMaxValue(root.right.left, map) + getMaxValue(root.right.right, map);
7750
}
7851
int max = Math.max(root.val + val,
79-
getMaxValue(root.left, map) + getMaxValue(root.right, map));
52+
getMaxValue(root.left, map) + getMaxValue(root.right, map));
8053
map.put(root, max);
8154
return max;
8255
}

0 commit comments

Comments
 (0)