/** * definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */publicclassSolution{publicList<String>binaryTreePaths(TreeNoderoot){List<String>ret=newLinkedList<String>();if(root==null)returnret;searchBT(root,""+root.val,ret);returnret;}publicvoidsearchBT(TreeNodenode,Stringpath,List<String>ret){if(node.left==null&&node.right==null)ret.add(path);if(node.left!=null)searchBT(node.left,path+"->"+node.left.val,ret);if(node.right!=null)searchBT(node.right,path+"->"+node.right.val,ret);}}