MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/BFS/1302. Deepest Leaves Sum/Sanghoo.java:9–33  ·  view source on GitHub ↗

https://leetcode.com/problems/deepest-leaves-sum/

Source from the content-addressed store, hash-verified

7 * https://leetcode.com/problems/deepest-leaves-sum/
8 */
9public class Sanghoo {
10
11 public int deepestLeavesSum(TreeNode root) {
12 Queue<TreeNode> q = new LinkedList<>();
13 int res = 0;
14
15 q.add(root);
16
17 while(!q.isEmpty()) {
18 int size = q.size();
19 res = 0; // 마지막 depth를 위해 초기화
20
21 for(int i=0; i<size; i++) {
22 TreeNode node = q.poll();
23
24 if(node.left != null) q.add(node.left);
25 if(node.right != null) q.add(node.right);
26
27 res += node.val;
28 }
29 }
30 return res;
31 }
32
33}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected