更新 0225.用队列实现栈 排版格式修复

This commit is contained in:
jinbudaily
2023-07-20 14:45:24 +08:00
parent 4b5e198b17
commit c18dbf0595

View File

@ -25,11 +25,11 @@
* 你所使用的语言也许不支持队列。 你可以使用 list 或者 deque双端队列来模拟一个队列 , 只要是标准的队列操作即可。 * 你所使用的语言也许不支持队列。 你可以使用 list 或者 deque双端队列来模拟一个队列 , 只要是标准的队列操作即可。
* 你可以假设所有操作都是有效的(例如, 对一个空的栈不会调用 pop 或者 top 操作)。 * 你可以假设所有操作都是有效的(例如, 对一个空的栈不会调用 pop 或者 top 操作)。
## 算法公开课
# 思路 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[队列的基本操作! | LeetCode225. 用队列实现栈](https://www.bilibili.com/video/BV1Fd4y1K7sm),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路
《代码随想录》算法公开课:[队列的基本操作! | LeetCode225. 用队列实现栈](https://www.bilibili.com/video/BV1Fd4y1K7sm),相信结合视频再看本篇题解,更有助于大家对链表的理解。
(这里要强调是单向队列) (这里要强调是单向队列)
@ -114,7 +114,7 @@ public:
* 时间复杂度: push为O(n)其他为O(1) * 时间复杂度: push为O(n)其他为O(1)
* 空间复杂度: O(n) * 空间复杂度: O(n)
# 优化 ## 优化
其实这道题目就是用一个队列就够了。 其实这道题目就是用一个队列就够了。
@ -162,9 +162,9 @@ public:
* 空间复杂度: O(n) * 空间复杂度: O(n)
# 其他语言版本 ## 其他语言版本
Java ### Java
使用两个 Queue 实现方法1 使用两个 Queue 实现方法1
```java ```java
@ -404,7 +404,7 @@ class MyStack {
} }
``` ```
Python ### Python
```python ```python
from collections import deque from collections import deque
@ -496,8 +496,7 @@ class MyStack:
return not self.que return not self.que
``` ```
### Go
Go
使用两个队列实现 使用两个队列实现
```go ```go
@ -628,9 +627,7 @@ func (this *MyStack) Empty() bool {
*/ */
``` ```
### JavaScript:
javaScript:
使用数组push, shift模拟队列 使用数组push, shift模拟队列
@ -740,7 +737,7 @@ MyStack.prototype.empty = function() {
``` ```
TypeScript: ### TypeScript:
版本一:使用两个队列模拟栈 版本一:使用两个队列模拟栈
@ -812,7 +809,7 @@ class MyStack {
} }
``` ```
Swift ### Swift:
```Swift ```Swift
// 定义一个队列数据结构 // 定义一个队列数据结构
@ -931,8 +928,9 @@ class MyStack {
} }
} }
``` ```
Scala: ### Scala:
使用两个队列模拟栈: 使用两个队列模拟栈:
```scala ```scala
import scala.collection.mutable import scala.collection.mutable
@ -1015,8 +1013,8 @@ class MyStack() {
} }
``` ```
### C#:
C#:
```csharp ```csharp
public class MyStack { public class MyStack {
Queue<int> queue1; Queue<int> queue1;
@ -1051,8 +1049,9 @@ public class MyStack {
} }
``` ```
PHP ### PHP:
> 双对列
> 双队列
```php ```php
// SplQueue 类通过使用一个双向链表来提供队列的主要功能。(PHP 5 >= 5.3.0, PHP 7, PHP 8) // SplQueue 类通过使用一个双向链表来提供队列的主要功能。(PHP 5 >= 5.3.0, PHP 7, PHP 8)
// https://www.php.net/manual/zh/class.splqueue.php // https://www.php.net/manual/zh/class.splqueue.php
@ -1130,6 +1129,8 @@ class MyStack {
} }
``` ```
### Rust:
> rust单队列 > rust单队列
```rust ```rust