12
12
13
13
## Stack 栈
14
14
15
- [ min-stack] ( https://leetcode-cn.com/problems/min-stack/ )
15
+ ### [ /implement-queue-using-stacks] ( https://leetcode.cn/problems/implement-queue-using-stacks )
16
+ > 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty):
17
+ > 实现 MyQueue 类:
18
+
19
+ > - void push(int x) 将元素 x 推到队列的末尾
20
+ > - int pop() 从队列的开头移除并返回元素
21
+ > - int peek() 返回队列开头的元素
22
+ > - boolean empty() 如果队列为空,返回 true ;否则,返回 false
23
+ > 说明:
24
+ > 你 只能 使用标准的栈操作 —— 也就是只有 push to top, peek/pop from top, size, 和 is empty 操作是合法的。
25
+ > 你所使用的语言也许不支持栈。你可以使用 list 或者 deque(双端队列)来模拟一个栈,只要是标准的栈操作即可。
26
+
27
+
28
+
29
+
30
+ ### [ min-stack] ( https://leetcode-cn.com/problems/min-stack/ )
16
31
17
32
> 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。
18
33
@@ -61,7 +76,7 @@ public:
61
76
* /
62
77
```
63
78
64
- [evaluate-reverse-polish-notation](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/)
79
+ ### [evaluate-reverse-polish-notation](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/)
65
80
66
81
> **波兰表达式计算** > **输入:** ["2", "1", "+", "3", "*"] > **输出:** 9
67
82
> **解释:** ((2 + 1) \* 3) = 9
@@ -88,7 +103,7 @@ int evalRPN(vector<string>& tokens) {
88
103
}
89
104
```
90
105
91
- [ decode-string] ( https://leetcode-cn.com/problems/decode-string/ )
106
+ ### [ decode-string] ( https://leetcode-cn.com/problems/decode-string/ )
92
107
93
108
> 给定一个经过编码的字符串,返回它解码后的字符串。
94
109
> s = "3[ a] 2[ bc] ", 返回 "aaabcbc".
@@ -164,7 +179,7 @@ boolean DFS(int root, int target) {
164
179
}
165
180
```
166
181
167
- [ binary-tree-inorder-traversal] ( https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ )
182
+ ### [ binary-tree-inorder-traversal] ( https://leetcode-cn.com/problems/binary-tree-inorder-traversal/ )
168
183
169
184
> 给定一个二叉树,返回它的* 中序* 遍历。
170
185
@@ -194,7 +209,7 @@ vector<int> inorderTraversal(TreeNode* root) {
194
209
}
195
210
```
196
211
197
- [clone-graph](https://leetcode-cn.com/problems/clone-graph/)
212
+ ### [clone-graph](https://leetcode-cn.com/problems/clone-graph/)
198
213
199
214
> 给你无向连通图中一个节点的引用,请你返回该图的深拷贝(克隆)。
200
215
@@ -221,7 +236,7 @@ Node* clone(Node* node, unordered_map<Node*, Node*>& visited){
221
236
}
222
237
```
223
238
224
- [ number-of-islands] ( https://leetcode-cn.com/problems/number-of-islands/ )
239
+ ### [ number-of-islands] ( https://leetcode-cn.com/problems/number-of-islands/ )
225
240
226
241
> 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计算岛屿的数量。一个岛被水包围,并且它是通过水平方向或垂直方向上相邻的陆地连接而成的。你可以假设网格的四个边均被水包围。
227
242
@@ -267,7 +282,7 @@ for(int i = 0; i < nums.size(); i++){
267
282
}
268
283
```
269
284
270
- [ largest-rectangle-in-histogram] ( https://leetcode-cn.com/problems/largest-rectangle-in-histogram/ )
285
+ ### [ largest-rectangle-in-histogram] ( https://leetcode-cn.com/problems/largest-rectangle-in-histogram/ )
271
286
272
287
> 给定 _ n_ 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。
273
288
> 求在该柱状图中,能够勾勒出来的矩形的最大面积。
@@ -309,7 +324,7 @@ int largestRectangleArea(vector<int>& heights) {
309
324
310
325
常用于 BFS 宽度优先搜索
311
326
312
- [implement-queue-using-stacks](https://leetcode-cn.com/problems/implement-queue-using-stacks/)
327
+ ### [implement-queue-using-stacks](https://leetcode-cn.com/problems/implement-queue-using-stacks/)
313
328
314
329
> 使用栈实现队列
315
330
@@ -396,7 +411,7 @@ vector<vector<int>> levelOrder(TreeNode* root){
396
411
}
397
412
```
398
413
399
- [01-matrix](https://leetcode-cn.com/problems/01-matrix/)
414
+ ### [01-matrix](https://leetcode-cn.com/problems/01-matrix/)
400
415
401
416
> 给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离。
402
417
> 两个相邻元素间的距离为 1
0 commit comments