[LeetCode]Binary Tree Paths
public class Solution { List<String> result = new ArrayList<String>(); public List<String> binaryTreePaths(TreeNode root) { if (root == null) { return result; } helper(root, ""); return result; } public void helper(TreeNode root, String str) { str = str + String.valueOf(root.val); if (root.left == null && root.right == null) { result.add(str); return; } str = str + "->"; if (root.left != null) { helper(root.left, str); } if (root.right != null) { helper(root.right, str); } } }