@@ -0,0 +1,1224 @@
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class _437PathSumIII %7B%0A    public int pathSum(TreeNode root, int sum) %7B%0A    %09if (root == null) return 0;%0A    %09int pathSum = 0;%0A    %09Map%3CTreeNode, Integer%3E map = new HashMap%3CTreeNode, Integer%3E();%0A    %09Map%3CTreeNode, Integer%3E mapAdd = new HashMap%3CTreeNode, Integer%3E();%0A        if (root.val == sum) pathSum++;%0A        if (root.left != null) map.put(root.left, root.val + root.left.val);%0A        if (root.right != null) map.put(root.right, root.val + root.right.val);%0A        while (!map.isEmpty())%7B%0A        %09for (TreeNode key : map.keySet()) %7B%0A        %09%09int v = map.get(key);%0A        %09%09if (v == sum) pathSum++;%0A%09    %09%09if (key.left != null) mapAdd.put(key.left, v + key.left.val);%0A%09    %09%09if (key.right != null) mapAdd.put(key.right, v + key.right.val);%0A        %09%7D%0A        %09map.clear();%0A        %09for (TreeNode key : mapAdd.keySet()) %7B%0A        %09%09int v = mapAdd.get(key);%0A        %09%09map.put(key, v);%0A        %09%7D%0A        %09mapAdd.clear();%0A        %7D%0A        pathSum += pathSum(root.left, sum);%0A        pathSum += pathSum(root.right, sum);%0A        return pathSum;%0A    %7D%0A    %0A%09public class TreeNode %7B%0A%09%09int val;%0A%09%09TreeNode left;%0A%09%09TreeNode right;%0A%09%09TreeNode(int x) %7B val = x; %7D%0A%09%7D%0A%7D%0A

Add 437 solution