## 110.平衡二叉树

``````class Solution {
public boolean isBalanced(TreeNode root) {
return getHeight(root) != -1;
}

private int getHeight(TreeNode cur){
if(cur == null) return 0;
int leftHeight = getHeight(cur.left);
if(leftHeight == -1) return -1;
int rightHeight = getHeight(cur.right);
if(rightHeight == -1) return -1;

if(Math.abs(leftHeight - rightHeight) > 1){
return -1;
}
return Math.max(leftHeight, rightHeight)+1;
}
}``````

## 257. 二叉树的所有路径

``````class Solution {
public List<String> binaryTreePaths(TreeNode root) {
List<String> res = new ArrayList<>();
if(root == null) return res;
List<Integer> paths = new ArrayList<>();
traveral(root, paths, res);
return res;
}

private void traveral(TreeNode node , List<Integer> paths, List<String> res){
if(node.left == null && node.right == null){
StringBuilder sb = new StringBuilder();
for(int i = 0; i < paths.size()-1; i++){
sb.append(paths.get(i)).append("->");
}
sb.append(paths.get(paths.size()-1));
}
if(node.left != null){
traveral(node.left, paths, res);
paths.remove(paths.size()-1);
}
if(node.right != null){
traveral(node.right, paths, res);
paths.remove(paths.size()-1);
}

}
}``````

## 404.左叶子之和

``````class Solution {
public int sumOfLeftLeaves(TreeNode root) {
if(root == null) return 0;
int leftvalue = sumOfLeftLeaves(root.left);
int rightvalue = sumOfLeftLeaves(root.right);

int midvalue = 0;
if(root.left != null && root.left.left == null && root.left.right == null){
midvalue = root.left.val;
}
return midvalue + leftvalue+rightvalue;
}
}``````