* Binary Tree Paths* 描述 Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: [“1->2->5”, “1->3”] 我的代码
一、[110]平衡二叉树 注意:注释的1、2两处得有返回值-1 class Solution {public boolean isBalanced(TreeNode root) {int result = getHeight(root);return result != (-1);}//高度public int getHeight(TreeNode node){if(node==null){r
Problem A: Jzzhu and Children(450A) Problem B: Jzzhu and Sequences(450B) Problem C:Jzzhu and Chocolate(449A) Problem D: Jzzhu and Cities(449B) Problem E:Jzzhu and Apples(4
思路:题目需要记录从根节点开始走的路径,无疑选用前序遍历,用一个数组paths 记录走过的节点信息,遇到叶子节点就用另一个list记录下路径,回溯时删掉paths尾节点即可 class Solution {public List<String> binaryTreePaths(TreeNode root) {List<String> list = new ArrayList<>(); //处
Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1/ \2 3\5 All root-to-leaf paths are: ["1->2->5", "1->3"] 题目分析:DFS即可 (16ms