Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit44ba403

Browse files
house robber III
1 parent50f293d commit44ba403

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎MEDIUM/src/medium/HouseRobberIII.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55

66
importclasses.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
publicclassHouseRobberIII {
933

1034
//simple recursion without cacheing: 1189 ms

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp