/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<String> binaryTreePaths(TreeNode root) {
List<String> rst = new ArrayList<String>();
if (root == null) {
return rst;
}
helper(root, String.valueOf(root.val), rst);
return rst;
}
private void helper(TreeNode root, String path, List<String> rst) {
if (root == null) {
return;
}
if (root.left == null && root.right == null) {
rst.add(path);
return;
}
if (root.left != null) {
helper(root.left, path + "->" + String.valueOf(root.left.val), rst);
}
if (root.right != null) {
helper(root.right, path + "->" + String.valueOf(root.right.val), rst);
}
}
}
如果是 full binary tree,时间复杂度?