Documentation
¶
Index ¶
- type BFSLevelTraversal
- type BSTreeFLCA
- type BTreeFLCA
- type BinarySqrt
- type BitQueens
- type BracketGenerator
- type CountDepth
- type DCCountDepth
- type DFSQueens
- type DPProduct
- type DefinitionVerifyBST
- type DivideConquerPow
- type DpLIS
- type FindLowestCommonAncestor
- type InOrderVerifyBST
- type IteratePow
- type LIS
- type LevelTraversal
- type Pow
- type Product
- type Queens
- type QueensII
- type RecursionBG
- type RecursionProduct
- type Sqrter
- type VerifyBST
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BFSLevelTraversal ¶
type BFSLevelTraversal struct {
// contains filtered or unexported fields
}
1. BFS O(n)
func NewBFSLevelTraversal ¶
func NewBFSLevelTraversal() *BFSLevelTraversal
func (*BFSLevelTraversal) LevelOrder ¶
func (bfs *BFSLevelTraversal) LevelOrder(root *module.TreeNode) [][]int
type BSTreeFLCA ¶
type BSTreeFLCA struct { }
235 二叉搜索树 根据大小判断
func (*BSTreeFLCA) LowestCommonAncestor ¶
func (bst *BSTreeFLCA) LowestCommonAncestor(root, p, q *module.TreeNode) *module.TreeNode
type BitQueens ¶
type BitQueens struct {
// contains filtered or unexported fields
}
1. 位运算 (最快) 用位运算实现
func (*BitQueens) TotalNQueens ¶
type BracketGenerator ¶
22 括号生成
type CountDepth ¶
type CountDepth interface { MinDepth(root *module.TreeNode) int MaxDepth(root *module.TreeNode) int }
104/111 二叉树的最大/最小深度
type DFSQueens ¶
type DFSQueens struct {
// contains filtered or unexported fields
}
func NewDFSQueens ¶
func NewDFSQueens() *DFSQueens
func (*DFSQueens) SolveNQueens ¶
type DefinitionVerifyBST ¶
type DefinitionVerifyBST struct { }
2. 递归 利用定义: 左子树(max) <= 当前节点 < 右子树(min) O(n)
func (*DefinitionVerifyBST) IsValidBST ¶
func (dv *DefinitionVerifyBST) IsValidBST(root *module.TreeNode) bool
type DivideConquerPow ¶
type DivideConquerPow struct { }
3. 分治 原理类似: 计算 2^8 = 2*2*2*2*2*2*2*2
2*2 = 4 2 * 2 2次 4*4 = 16 2*2 * 2*2 4次 16*16 = 256 2*2*2*2 * 2*2*2*2 8次 总共需要3次计算
type DpLIS ¶
type DpLIS struct { }
- DP O(n^2) 定义 DP[i]: 选择第 i 个元素时的最长上升子序列 Max(DP[0], ..., DP[i-1]) = DP[j] DP[i] = DP[j] + 1
func (*DpLIS) LengthOfLIS ¶
type FindLowestCommonAncestor ¶
type FindLowestCommonAncestor interface { // 感觉题目给 p, q 的指针不太合理, 应该使用 int LowestCommonAncestor(root, p, q *module.TreeNode) *module.TreeNode }
235/236(二叉搜索树/二叉树) 的最近公共祖先 说明:
所有节点的值都是唯一的。 p、q 为不同节点且均存在于给定的二叉搜索树中。
type InOrderVerifyBST ¶
type InOrderVerifyBST struct {
// contains filtered or unexported fields
}
1. 递归 中序遍历的结果是升序的. 这里只保存前驱节点的值, 而不必保存中序遍历的完整结果. O(n)
func (*InOrderVerifyBST) IsValidBST ¶
func (iov *InOrderVerifyBST) IsValidBST(root *module.TreeNode) bool
type LevelTraversal ¶
102 层遍历二叉树
type RecursionBG ¶
type RecursionBG struct {
// contains filtered or unexported fields
}
3. 改进方法2
- 生成时按照一定规则
规律是一个一个往后添加 "(/)"
func (*RecursionBG) GenerateParenthesis ¶
func (rbg *RecursionBG) GenerateParenthesis(n int) []string
type RecursionProduct ¶
type RecursionProduct struct {
// contains filtered or unexported fields
}
1. 暴力 Recursion 每个数字进行抉择: 乘, 不乘
func (*RecursionProduct) MaxProduct ¶
func (rp *RecursionProduct) MaxProduct(nums []int) int
Click to show internal directories.
Click to hide internal directories.