/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/funcgetDept(root *TreeNode)int{if root ==nil{return0}returnmax(getDept(root.Left),getDept(root.Right))+1}func abs (a int)int{if a >=0{return a
}return-a
}funcisBalanced(root *TreeNode)bool{if root ==nil{returntrue}returnisBalanced(root.Left)&&isBalanced(root.Right)&&abs(getDept(root.Left)-getDept(root.Right))<=1}
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/var res []stringvar nodeList []*TreeNode
funcreadStack(){
temp :=""for i :=0; i <len(nodeList); i++{
temp += strconv.Itoa(nodeList[i].Val)if i !=len(nodeList)-1{
temp +="->"}}if temp !=""{
res =append(res, temp)}}funcdfs(root *TreeNode){if root ==nil{return}// visit
nodeList =append(nodeList, root)if root.Left ==nil&& root.Right ==nil{readStack()}dfs(root.Left)dfs(root.Right)// back
nodeList = nodeList[:len(nodeList)-1]// 删除最后一个元素}funcbinaryTreePaths(root *TreeNode)[]string{
res =[]string{}
nodeList =[]*TreeNode{}dfs(root)return res
}
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/var sum =0func dfs (root *TreeNode){if root ==nil{return}if root.Left !=nil{if root.Left.Left ==nil&& root.Left.Right ==nil{
sum += root.Left.Val
}dfs(root.Left)}dfs(root.Right)}funcsumOfLeftLeaves(root *TreeNode)int{
sum =0dfs(root)return sum
}