包含标签 二叉树 的文章

第六章 二叉树part09

0 条评论 算法 算法基础 二叉树 Greyson
669. 修剪二叉搜索树 /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } 3 1 4 2 */ func trimBST(root *TreeNode, ...

第六章 二叉树part08

0 条评论 算法 算法基础 二叉树 Greyson
235. 二叉搜索树的最近公共祖先 func lowestCommonAncestor(root, p, q *TreeNode) *TreeNode { if p.Val > q.Val { return lowestCommonAncestor(root, q, p) } rootVal := root.Val lVal := p...

第六章 二叉树 part05

0 条评论 算法 算法基础 二叉树 Greyson
513.找树左下角的值 先序遍历 /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ var depth int var res int var maxDep int fu...

第六章 二叉树part04

0 条评论 算法 算法基础 二叉树 Greyson
110.平衡二叉树 递归 /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func getDept(root *TreeNode) int { if root =...

第六章 二叉树part03

0 条评论 算法 算法基础 二叉树 Greyson
104.二叉树的最大深度 二叉树 /** * Definition for a Node. * type Node struct { * Val int * Children []*Node * } */ var res int var dept int func dfs(root *Node) { if root == nil { retu...

第六章 二叉树 part02

0 条评论 算法 算法基础 二叉树 Greyson
二叉树层序遍历登场! 二叉树的层序遍历 /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ var q []*TreeNode var head int var ...

第六章 二叉树part01

0 条评论 算法 算法基础 二叉树 Greyson
二叉树的递归遍历 二叉树的递归遍历 二叉树的统一迭代法