-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitBook: [master] 49 pages and 27 assets modified
- Loading branch information
1 parent
ca50c7a
commit c4d8ed4
Showing
75 changed files
with
1,292 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 参考文献 | ||
|
||
\[1\] labuladong的算法小抄: [https://labuladong.gitbook.io/algo/](https://labuladong.gitbook.io/algo/) | ||
|
||
\[2\] 算法第四版: [https://book.douban.com/subject/19952400/](https://book.douban.com/subject/19952400/) | ||
|
||
\[3\] [play-with-Data-Struces](https://github.com/liuyubobobo/Play-with-Data-Structures) | ||
|
||
\[4\] [problem-solving-with-algorithms-and-data-structure-using-pytho](https://runestone.academy/runestone/books/published/pythonds/index.html), 以及[中文版本](https://github.com/facert/python-data-structure-cn) | ||
|
||
\[5\] [williamfiset/Algorithms](https://github.com/williamfiset/Algorithms) | ||
|
||
## 滑动窗口 | ||
|
||
\[1\] [https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/solution/shi-yao-shi-hua-dong-chuang-kou-yi-ji-ru-he-yong-h/](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/solution/shi-yao-shi-hua-dong-chuang-kou-yi-ji-ru-he-yong-h/) | ||
|
||
## 动态规划 | ||
|
||
\[1\] Nikola Otasevic: [Follow these steps to solve any Dynamic Programming interview problem](https://medium.com/free-code-camp/follow-these-steps-to-solve-any-dynamic-programming-interview-problem-cc98e508cd0e) | ||
|
||
\[2\] Alaina Kafkes: [Demystifying Dynamic Programming](https://medium.com/free-code-camp/demystifying-dynamic-programming-3efafb8d4296) | ||
|
||
\[3\] Oleksii Trekhleb: [Dynamic Programming vs Divide-and-Conquer](https://itnext.io/dynamic-programming-vs-divide-and-conquer-2fea680becbe) | ||
|
||
\[4\] Vaidehi Joshi: [Less Repetition, More Dynamic Programming](https://medium.com/basecs/less-repetition-more-dynamic-programming-43d29830a630) | ||
|
||
\[5\] Coding Freak: [Top 50 Dynamic Programming Practice Problems](https://blog.usejournal.com/top-50-dynamic-programming-practice-problems-4208fed71aa3) | ||
|
||
\[6\] HankingHu: [动态规划 Dynamic Programming--从菜鸟到老鸟](https://blog.csdn.net/u013309870/article/details/75193592) | ||
|
||
## 算法可视化 | ||
|
||
\[1\] VisuAlgo: [https://visualgo.net/zh](https://visualgo.net/zh) | ||
|
||
\[2\] [https://www.cs.usfca.edu/~galles/visualization/about.html](https://www.cs.usfca.edu/~galles/visualization/about.html) | ||
|
||
\[3\] [https://algorithm-visualizer.org/](https://algorithm-visualizer.org/) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 基本概念 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 串基本概念 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 基本概念 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 基本概念 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 存储结构 | ||
|
||
## 顺序存储结构 | ||
|
||
树的顺序存储结构也称为树的顺序存储结构的双亲表示法,很好理解也很好实现,使用一维数组即可。 | ||
|
||
![](../.gitbook/assets/image%20%2820%29.png) | ||
|
||
如图所示,结点1的双亲是0,故在数组中存储其双亲的下标0,结点5的双亲是2,故在数组中存储其双亲的下标为2,结点0为根结点故将其值标记为-1。 | ||
|
||
## 链式存储结构 | ||
|
||
链式存储结构主要有两种方式 | ||
|
||
### 孩子存储结构 | ||
|
||
|
||
|
||
### 孩子兄弟存储结构 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 二叉排序树 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 二叉树 | ||
|
||
## 定义 | ||
|
||
1. 每个节点最多只有两颗子树,即二叉树中结点的度只能为0,1,2。 | ||
2. 子树有左右顺序之分不能颠倒。 | ||
|
||
## 二叉树的五种形态 | ||
|
||
* 空二叉树 | ||
* 只有根结点 | ||
* 只有左子树 | ||
* 只有右子树 | ||
* 左右子树都有 | ||
|
||
## 满二叉树 | ||
|
||
在一棵二叉树中,如果所有的分支结点都有左孩子和右孩子结点,并且叶子结点都集中在二叉树的最下一层,则这样的二叉树称为满二叉树。下图就是一颗满二叉树 | ||
|
||
![](../../.gitbook/assets/image%20%288%29.png) | ||
|
||
## 完全二叉树 | ||
|
||
完全二叉树一定是一个满二叉树,从右到左,从下到上,**挨个**删除结点的到的。 | ||
|
||
![](../../.gitbook/assets/image%20%2816%29.png) | ||
|
||
粉红色代表删除的结点 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
# 遍历算法 | ||
|
||
## 先序遍历 | ||
|
||
先序遍历算法流程如下: | ||
|
||
1. 访问根结点 | ||
2. 先序遍历左子树 | ||
3. 先序遍历右子树 | ||
|
||
{% tabs %} | ||
{% tab title="递归方式" %} | ||
```go | ||
func Preorder(node *TreeNode){ | ||
if *node != (tree.BTNode{}) && node != nil{ | ||
fmt.Printf("%s", node.Val) | ||
PreShowTree(node.Left) | ||
PreShowTree(node.Right) | ||
} | ||
} | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="非递归方式" %} | ||
``` | ||
func PreShow(node *tree.BTNode){ | ||
if *node != (tree.BTNode{}) && node != nil{ | ||
stack := &sequential_stack.Stack{} | ||
stack.InitStack() | ||
stack.Push(node) | ||
for !stack.IsEmpty(){ | ||
temp, err := stack.Pop() | ||
btNode := temp.(*tree.BTNode) | ||
if err == nil{ | ||
fmt.Println(btNode.Val) | ||
if *btNode.Left != (tree.BTNode{}) && btNode.Left != nil{ | ||
stack.Push(btNode.Left) | ||
} | ||
if *btNode.Right != (tree.BTNode{}) && btNode.Right != nil{ | ||
stack.Push(btNode.Right) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## 中序遍历 | ||
|
||
中序遍历算法流程如下: | ||
|
||
1. 中序遍历左子树 | ||
2. 访问根结点 | ||
3. 中序遍历右子树 | ||
|
||
{% tabs %} | ||
{% tab title="递归方式" %} | ||
```go | ||
func InShowTree(node *model.Node){ | ||
if *node != (tree.BTNode{}) && node != nil{ | ||
PreShowTree(node.Left) | ||
fmt.Printf("%s", node.Val) | ||
PreShowTree(node.Right) | ||
} | ||
} | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="非递归方式" %} | ||
``` | ||
``` | ||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## 后序遍历 | ||
|
||
后序遍历算法流程如下: | ||
|
||
1. 后后序遍历左子树 | ||
2. 后序遍历右子树 | ||
3. 访问根结点 | ||
|
||
{% tabs %} | ||
{% tab title="递归方式" %} | ||
```go | ||
func PostShowTree(node *model.Node){ | ||
if *node != (tree.BTNode{}) && node != nil{ | ||
PreShowTree(node.Left) | ||
PreShowTree(node.Right) | ||
fmt.Printf("%s", node.Val) | ||
} | ||
} | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="非递归方式" %} | ||
``` | ||
``` | ||
{% endtab %} | ||
{% endtabs %} | ||
|
||
## 层次遍历 | ||
|
||
|
||
|
||
{% tabs %} | ||
{% tab title="递归方式" %} | ||
```go | ||
var leveles = make([][]int, 0) | ||
|
||
func levelOrder1(root *TreeNode) [][]int { | ||
if root == nil{ | ||
return leveles | ||
} | ||
helper(root, 0) | ||
return leveles | ||
} | ||
|
||
func helper(node *TreeNode, level int){ | ||
if len(leveles) == level{ | ||
leveles = append(leveles, make([]int, 0)) | ||
} | ||
|
||
leveles[level] = append(leveles[level], node.Val) | ||
|
||
if node.Left != nil{ | ||
helper(node.Left, level + 1) | ||
} | ||
if node.Right != nil{ | ||
helper(node.Right, level + 1) | ||
} | ||
} | ||
``` | ||
{% endtab %} | ||
|
||
{% tab title="非递归方式" %} | ||
```go | ||
func levelOrder(root *TreeNode) [][]int { | ||
leveles = make([][]int , 0) | ||
|
||
if root == nil{ | ||
return leveles | ||
} | ||
queue := make([]*TreeNode, 0) | ||
queue = append(queue, root) | ||
level := 0 | ||
for len(queue) != 0{ | ||
leveles = append(leveles, make([]int ,0)) | ||
level_length := len(queue) | ||
for i := 0; i < level_length; i++{ | ||
node := queue[0] | ||
queue = queue[1:] | ||
leveles[level] = append(leveles[level], node.Val) | ||
if node.Left != nil{ | ||
queue = append(queue, node.Left) | ||
} | ||
if node.Right != nil{ | ||
queue = append(queue, node.Right) | ||
} | ||
} | ||
level++ | ||
} | ||
return leveles | ||
} | ||
``` | ||
{% endtab %} | ||
{% endtabs %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 常见算法 | ||
|
39 changes: 39 additions & 0 deletions
39
...-shu/chang-jian-suan-fa/cong-shang-dao-xia-da-yin-er-cha-shu-ceng-ci-bian-li.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 从上倒下打印二叉树/层次遍历 | ||
|
||
## 题目描述 | ||
|
||
从上到下打印出二叉树的每个节点,同一层的节点按照从左到右的顺序打印。 | ||
|
||
![](../../../.gitbook/assets/image%20%282%29.png) | ||
|
||
提示: | ||
|
||
`节点总数 <= 1000` | ||
|
||
{% hint style="info" %} | ||
来源:力扣(LeetCode) 链接:[https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof) 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 | ||
{% endhint %} | ||
|
||
## 题解 | ||
|
||
```go | ||
func levelOrder(root *TreeNode) []int { | ||
if root == nil{ | ||
return nil | ||
} | ||
buff := make([]*TreeNode, 0) | ||
buff = append(buff, root) | ||
result := make([]int, 0) | ||
for len(buff) != 0{ | ||
temp := buff[0] | ||
if temp != nil{ | ||
result = append(result, temp.Val) | ||
buff = append(buff, temp.Left) | ||
buff = append(buff, temp.Right) | ||
} | ||
buff = buff[1:] | ||
} | ||
return result | ||
} | ||
``` | ||
|
49 changes: 49 additions & 0 deletions
49
shu/er-cha-shu/chang-jian-suan-fa/dui-cheng-de-er-cha-shu.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# 对称的二叉树 | ||
|
||
## 题目描述 | ||
|
||
请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 | ||
|
||
![](../../../.gitbook/assets/image%20%2819%29.png) | ||
|
||
示例 1: | ||
|
||
```text | ||
输入:root = [1,2,2,3,4,4,3] | ||
输出:true | ||
``` | ||
|
||
示例 2: | ||
|
||
```text | ||
输入:root = [1,2,2,null,3,null,3] | ||
输出:false | ||
``` | ||
|
||
限制: | ||
|
||
`0 <= 节点个数 <= 1000` | ||
|
||
{% hint style="info" %} | ||
来源:力扣(LeetCode) 链接:[https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof) 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 | ||
{% endhint %} | ||
|
||
## 题解 | ||
|
||
```go | ||
func isSymmetric(root *TreeNode) bool { | ||
return symmetric(root, root) | ||
} | ||
|
||
func symmetric(left *TreeNode, right *TreeNode) bool{ | ||
if left == nil && right == nil{ | ||
return true | ||
}else if left == nil || right == nil{ | ||
return false | ||
}else if left.Val != right.Val{ | ||
return false | ||
} | ||
return symmetric(left.Left, right.Right) && symmetric(left.Right, right.Left) | ||
} | ||
``` | ||
|
Oops, something went wrong.