@@ -0,0 +1,1024 @@
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Apublic class _257BinaryTreePaths %7B%0A    public List%3CString%3E binaryTreePaths(TreeNode root) %7B%0A        List%3CString%3E list = new ArrayList%3CString%3E();%0A        Map%3CTreeNode, String%3E map = new HashMap%3CTreeNode, String%3E();%0A        if (root != null)  map.put(root, String.valueOf(root.val));%0A        while (!map.isEmpty()) %7B%0A            Map%3CTreeNode, String%3E newMap = new HashMap%3CTreeNode, String%3E();%0A        %09for (TreeNode key : map.keySet()) %7B%0A        %09%09String path = map.get(key);%0A        %09%09if (key.left == null && key.right == null) list.add(path);%0A        %09%09else %7B%0A%09        %09%09if (key.left != null) newMap.put(key.left, path + %22-%3E%22 + key.left.val);%0A%09        %09%09if (key.right != null) newMap.put(key.right, path + %22-%3E%22 + key.right.val);%0A        %09%09%7D%0A        %09%7D%0A        %09map = newMap;%0A        %7D%0A        return list;%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 257 solution