Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2ae00ce

Browse files
committedOct 25, 2020
GitBook: [master] 7 pages modified
1 parent 2f4cdf7 commit 2ae00ce

File tree

7 files changed

+187
-39
lines changed

7 files changed

+187
-39
lines changed
 

‎SUMMARY.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@
193193
* [0198.House-Robber](docs/leetcode/101-200/0198.house-robber.md)
194194
* [0199.Binary-Tree-Right-Side-View](docs/leetcode/101-200/0199.binary-tree-right-side-view.md)
195195
* [0200.Number-of-Islands](docs/leetcode/101-200/0200.number-of-islands.md)
196-
* [201-200](docs/leetcode/101-200/README.md)
197-
* [0101.Symmetric-Tree](docs/leetcode/101-200/0101.symmetric-tree.md)
198-
* [301-400](docs/leetcode/101-200/README.md)
199-
* [0322.Symmetric-Tree](docs/leetcode/301-400/0322.coin-change.md)
196+
* [201-200](docs/leetcode/101-200-1/README.md)
197+
* [0101.Symmetric-Tree](docs/leetcode/101-200-1/0101.symmetric-tree.md)
198+
* [301-400](docs/leetcode/101-200-2/README.md)
199+
* [0322.Coin-Change](docs/leetcode/101-200-2/0322.coin-change.md)
200+

‎docs/jzof/of006.md

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,66 +25,60 @@ description: 剑指 Offer 06. 从尾到头打印链表
2525

2626
**算法流程:**
2727

28-
1.
29-
**复杂度分析:**
30-
31-
* **时间复杂度**$$O(N)$$****遍历N次,递归 N 次
32-
* **空间复杂度**$$O(N)$$****递归 N 次,开辟 N 个栈空间
28+
1. **复杂度分析:**
29+
2. **时间复杂度**$$O(N)$$****遍历N次,递归 N 次
30+
3. **空间复杂度**$$O(N)$$****递归 N 次,开辟 N 个栈空间
3331

3432
#### 代码
3533

3634
{% tabs %}
3735
{% tab title="Go" %}
3836
```go
3937
func reversePrint(head *ListNode) []int {
40-
ans := make([]int, 0)
41-
if head == nil {
42-
return ans
43-
}
44-
ans = reversePrint(head.Next)
45-
ans = append(ans, head.Val)
46-
return ans
38+
ans := make([]int, 0)
39+
if head == nil {
40+
return ans
41+
}
42+
ans = reversePrint(head.Next)
43+
ans = append(ans, head.Val)
44+
return ans
4745
}
4846
```
4947
{% endtab %}
5048
{% endtabs %}
5149

52-
###
53-
5450
### 思路1 : 多指针
5551

5652
多个指针辅助,一次遍历
5753

5854
**算法流程:**
5955

60-
1.
61-
**复杂度分析:**
62-
63-
* **时间复杂度**$$O(N)$$****遍历N次,递归 N 次
64-
* **空间复杂度**$$O(N)$$****递归 N 次,开辟 N 个栈空间
56+
1. **复杂度分析:**
57+
2. **时间复杂度**$$O(N)$$****遍历N次,递归 N 次
58+
3. **空间复杂度**$$O(N)$$****递归 N 次,开辟 N 个栈空间
6559

6660
#### 代码
6761

6862
{% tabs %}
6963
{% tab title="Go" %}
7064
```go
7165
func reversePrint(head *ListNode) []int {
72-
if head == nil {
73-
return []int{}
74-
}
75-
pre, cur, next, ans := &ListNode{}, head, head.Next, []int{}
76-
for cur != nil {
77-
next = cur.Next
78-
cur.Next = pre
79-
80-
pre = cur
81-
cur = next
82-
}
83-
for pre.Next != nil {
84-
ans = append(ans, pre.Val)
85-
pre = pre.Next
86-
}
87-
return ans
66+
if head == nil {
67+
return []int{}
68+
}
69+
pre, cur, next, ans := &ListNode{}, head, head.Next, []int{}
70+
for cur != nil {
71+
next = cur.Next
72+
cur.Next = pre
73+
74+
pre = cur
75+
cur = next
76+
}
77+
for pre.Next != nil {
78+
ans = append(ans, pre.Val)
79+
pre = pre.Next
80+
}
81+
return ans
8882
}
8983
```
9084
{% endtab %}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 0101.Symmetric-Tree
2+
3+
## Description
4+
5+
Given a binary tree, check whether it is a mirror of itself \(ie, symmetric around its center\).
6+
7+
For example, this binary tree `[1,2,2,3,4,4,3]` is symmetric:
8+
9+
```text
10+
1
11+
/ \
12+
2 2
13+
/ \ / \
14+
3 4 4 3
15+
```
16+
17+
But the following `[1,2,2,null,3,null,3]` is not:
18+
19+
```text
20+
1
21+
/ \
22+
2 2
23+
\ \
24+
3 3
25+
```
26+
27+
**Note:**
28+
29+
Bonus points if you could solve it both recursively and iteratively.
30+
31+
**Tags:** Tree, Depth-first Search, Breadth-first Search
32+
33+
## 题意
34+
35+
> 题意是判断一棵二叉树是否左右对称
36+
37+
## 题解
38+
39+
### 思路1
40+
41+
> 用深度搜索,比较根结点的左右两棵子树是否对称,如果左右子树的值相同,那么再分别对左子树的左节点和右子树的右节点,左子树的右节点和右子树的左节点做比较即可。
42+
43+
```go
44+
func isSymmetric(root *TreeNode) bool {
45+
return root == nil || isSymmetricHelper(root.Left, root.Right)
46+
}
47+
48+
func isSymmetricHelper(left *TreeNode, right *TreeNode) bool {
49+
50+
if left == nil || right == nil {
51+
return left == right
52+
}
53+
54+
// 检查节点的值
55+
if left.Val != right.Val {
56+
return false
57+
}
58+
return isSymmetricHelper(left.Left, right.Right) &&
59+
isSymmetricHelper(left.Right, right.Left)
60+
}
61+
```
62+
63+
### 思路2
64+
65+
> 思路2 \`\`\`go
66+
67+
\`\`\`
68+
69+
## 结语
70+
71+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode](https://github.com/kylesliu/awesome-golang-algorithm)
72+

‎docs/leetcode/101-200-1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 201-200
2+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
description: 322. 零钱兑换
3+
---
4+
5+
# 0322.Coin-Change
6+
7+
## 题目描述
8+
9+
[题目地址](https://leetcode.com/problems/coin-change/)
10+
11+
给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。
12+
13+
你可以认为每种硬币的数量是无限的。
14+
15+
### **示例 1:**
16+
17+
```go
18+
输入:coins = [1, 2, 5], amount = 11
19+
输出:3
20+
解释:11 = 5 + 5 + 1
21+
```
22+
23+
## 题解
24+
25+
### 思路1 : **动态规划-自上而下**
26+
27+
**算法流程:**
28+
29+
![](https://assets.leetcode.com/static_assets/media/original_images/322_coin_change_tree.png)
30+
31+
\*\*\*\*
32+
33+
**复杂度分析:**
34+
35+
* **时间复杂度**$$O(N)$$****
36+
* **空间复杂度**$$O(N)$$****
37+
38+
#### 代码
39+
40+
{% tabs %}
41+
{% tab title="Go" %}
42+
```go
43+
func coinChange(coins []int, amount int) int {
44+
dp := make([]int, amount+1)
45+
for i := 0; i < amount+1; i++ {
46+
dp[i] = amount + 1
47+
}
48+
dp[0] = 0
49+
50+
for i := 1; i <= amount; i++ {
51+
for j := 0; j < len(coins); j++ {
52+
if coins[j] <= i {
53+
dp[i] = min(dp[i], dp[i-coins[j]]+1)
54+
55+
}
56+
}
57+
}
58+
if dp[amount] > amount {
59+
return -1
60+
}
61+
return dp[amount]
62+
}
63+
64+
func min(x, y int) int {
65+
if x > y {
66+
return y
67+
}
68+
return x
69+
}
70+
```
71+
{% endtab %}
72+
{% endtabs %}
73+
74+
## 总结
75+
76+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 算法 题解:[awesome-golang-algorithm](https://github.com/kylesliu/awesome-golang-algorithm)
77+

‎docs/leetcode/101-200-2/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 301-400
2+

‎docs/leetcode/301-400/0322.coin-change.md

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.