@@ -0,0 +1,1346 @@
+package leetcode;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * https://leetcode.com/problems/deepest-leaves-sum/%0A */%0Apublic class Problem1302 %7B%0A    public static class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public int deepestLeavesSum(TreeNode root) %7B%0A        IntRef maxLevel = new IntRef();%0A        Map%3CInteger, Integer%3E levelSum = new HashMap%3C%3E();%0A        deepestLeavesSum(root, 0, maxLevel, levelSum);%0A        return levelSum.get(maxLevel.value);%0A    %7D%0A%0A    private static class IntRef %7B%0A        private int value;%0A    %7D%0A%0A    private static void deepestLeavesSum(TreeNode root, int level, IntRef maxLevel,%0A                                         Map%3CInteger, Integer%3E levelSum) %7B%0A        if (root == null) %7B%0A            return;%0A        %7D%0A        maxLevel.value = Math.max(maxLevel.value, level);%0A        if (root.left == null && root.right == null) %7B%0A            if (!levelSum.containsKey(level)) %7B%0A                levelSum.put(level, root.val);%0A            %7D else %7B%0A                levelSum.put(level, levelSum.get(level) + root.val);%0A            %7D%0A            return;%0A        %7D%0A        deepestLeavesSum(root.left, level + 1, maxLevel, levelSum);%0A        deepestLeavesSum(root.right, level + 1, maxLevel, levelSum);%0A    %7D%0A%7D%0A

Solve problem 1302