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

Commit3b0e0a8

Browse files
authored
Merge pull requestneetcode-gh#2532 from Anukriti167/patch-9
Create 0337-house-robber-iii.java
2 parents423062b +2cdea0c commit3b0e0a8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎java/0337-house-robber-iii.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classSolution {
2+
publicint[]dfs(TreeNoderoot){
3+
if(root ==null)returnnewint[2];
4+
5+
int []left =dfs(root.left);
6+
int []right =dfs(root.right);
7+
8+
int []res =newint[2];
9+
10+
res[0] =left[1] +right[1] +root.val;//with Root
11+
res[1] =Math.max(left[0],left[1]) +Math.max(right[0],right[1]);//without Root
12+
13+
returnres;
14+
}
15+
publicintrob(TreeNoderoot) {
16+
int []ans =dfs(root);
17+
returnMath.max(ans[0],ans[1]);
18+
}
19+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp