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

Commitdc29c0f

Browse files
add a solution for 1302
1 parent25ba7da commitdc29c0f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_1302.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,27 @@ private int maxDepth(TreeNode root) {
4343
returnMath.max(maxDepth(root.left),maxDepth(root.right)) +1;
4444
}
4545
}
46+
47+
publicstaticclassSolution2 {
48+
publicintdeepestLeavesSum(TreeNoderoot) {
49+
Queue<TreeNode>queue =newLinkedList<>();
50+
queue.offer(root);
51+
intsum =0;
52+
while (!queue.isEmpty()) {
53+
intsize =queue.size();
54+
sum =0;
55+
for (inti =0;i <size;i++) {
56+
TreeNodecurr =queue.poll();
57+
sum +=curr.val;
58+
if (curr.left !=null) {
59+
queue.offer(curr.left);
60+
}
61+
if (curr.right !=null) {
62+
queue.offer(curr.right);
63+
}
64+
}
65+
}
66+
returnsum;
67+
}
68+
}
4669
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp