?LeetCode刷題實戰(zhàn)257:二叉樹的所有路徑
Given the root of a binary tree, return all root-to-leaf paths in any order.
A leaf is a node with no children.

解題

/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public List<String> binaryTreePaths(TreeNode root) {
List<String> list = new LinkedList<>();
helper(root, "", list);
return list;
}
private void helper(TreeNode root, String s, List<String>list){
if (root == null){
return;
}
s = s + root.val;
if (root.left == null && root.right == null){
list.add(s);
return;
}
if (root.left != null){
helper(root.left, s + "->", list);
}
if (root.right != null){
helper(root.right, s + "->", list);
}
}
}
LeetCode刷題實戰(zhàn)241:為運算表達式設計優(yōu)先級
LeetCode刷題實戰(zhàn)242:有效的字母異位詞
LeetCode刷題實戰(zhàn)244:最短單詞距離 II
LeetCode刷題實戰(zhàn)245:最短單詞距離 III
LeetCode刷題實戰(zhàn)246:中心對稱數(shù)
LeetCode刷題實戰(zhàn)247:中心對稱數(shù)II
LeetCode刷題實戰(zhàn)248:中心對稱數(shù)III
LeetCode刷題實戰(zhàn)250:統(tǒng)計同值子樹
