包含标签 算法基础 的文章

第八章 贪心算法 part01

0 条评论 算法 算法基础 贪心 Greyson
455.分发饼干 func findContentChildren(g []int, s []int) int { sort.Ints(g) sort.Ints(s) i := 0 j := 0 res := 0 for i < len(g) && j < len(s) { if g[i] <= s...

28 第七章 回溯算法

0 条评论 算法 算法基础 回溯 Greyson
93.复原IP地址 回溯,细节多 var res []string var offsets []int func valid(s string) bool { if len(s) > 1 && s[0] == '0' { return false } parseInt, _ := strconv.ParseInt(s, 10, ...

第七章 回溯算法part02

0 条评论 算法 算法基础 回溯 Greyson
216.组合总和III 回溯 var temp = []int{} var res = [][]int{} var mp = make([]bool, 10) func sumTarget(target int) bool{ sum := 0 for i := 0; i < len(temp); i++ { sum += temp[i] } ...

第六章 二叉树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
二叉树的递归遍历 二叉树的递归遍历 二叉树的统一迭代法