Skip to content

Commit 44ba403

Browse files
house robber III
1 parent 50f293d commit 44ba403

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

MEDIUM/src/medium/HouseRobberIII.java

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55

66
import classes.TreeNode;
77

8+
/**337. House Robber III QuestionEditorial Solution My Submissions
9+
Total Accepted: 19180
10+
Total Submissions: 49342
11+
Difficulty: Medium
12+
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will automatically contact the police if two directly-linked houses were broken into on the same night.
13+
14+
Determine the maximum amount of money the thief can rob tonight without alerting the police.
15+
16+
Example 1:
17+
3
18+
/ \
19+
2 3
20+
\ \
21+
3 1
22+
Maximum amount of money the thief can rob = 3 + 3 + 1 = 7.
23+
Example 2:
24+
3
25+
/ \
26+
4 5
27+
/ \ \
28+
1 3 1
29+
Maximum amount of money the thief can rob = 4 + 5 = 9.
30+
Credits:
31+
Special thanks to @dietpepsi for adding this problem and creating all test cases.*/
832
public class HouseRobberIII {
933

1034
//simple recursion without cacheing: 1189 ms

0 commit comments

Comments
 (0)