Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 14 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
7d92df3
Update 0309.最佳买卖股票时机含冷冻期.md about rust
fwqaaq Jun 30, 2023
fc2a54a
Merge pull request #2160 from fwqaaq/patch-41
youngyangyang04 Jul 20, 2023
c3ebc91
更新 双指针总结 排版格式修复
jinbudaily Jul 20, 2023
de770c6
更新 栈与队列理论基础 排版格式修复
jinbudaily Jul 20, 2023
4b5e198
更新 0232.用栈实现队列 排版格式修复
jinbudaily Jul 20, 2023
c18dbf0
更新 0225.用队列实现栈 排版格式修复
jinbudaily Jul 20, 2023
a1ef2d0
更新 020.有效的括号 排版格式修复
jinbudaily Jul 20, 2023
70888c2
更新 1047.删除字符串中的所有相邻重复项 排版格式修复
jinbudaily Jul 20, 2023
7f4d740
更新 0150.逆波兰表达式求值 排版格式修复
jinbudaily Jul 20, 2023
5a6bf6d
更新 0239.滑动窗口最大值 排版格式修复
jinbudaily Jul 20, 2023
0e4f91d
更新 0347.前k个高频元素 排版格式修复
jinbudaily Jul 20, 2023
f7b87e6
更新 栈与队列总结 排版格式修复
jinbudaily Jul 20, 2023
5d76e86
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 20, 2023
e6b208a
Merge pull request #2194 from jinbudaily/master
youngyangyang04 Jul 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
更新 0239.滑动窗口最大值 排版格式修复
  • Loading branch information
jinbudaily committed Jul 20, 2023
commit 5a6bf6d85534e304e73460d67db006f5c1475657
37 changes: 21 additions & 16 deletions problems/0239.滑动窗口最大值.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
* -10^4 <= nums[i] <= 10^4
* 1 <= k <= nums.length

## 算法公开课

**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[单调队列正式登场!| LeetCode:239. 滑动窗口最大值](https://www.bilibili.com/video/BV1XS4y1p7qj),相信结合视频再看本篇题解,更有助于大家对本题的理解**。

# 思路

《代码随想录》算法视频公开课:[单调队列正式登场!| LeetCode:239. 滑动窗口最大值](https://www.bilibili.com/video/BV1XS4y1p7qj),相信结合视频在看本篇题解,更有助于大家对本题的理解。
## 思路

这是使用单调队列的经典题目。

Expand Down Expand Up @@ -196,18 +196,18 @@ public:

空间复杂度因为我们定义一个辅助队列,所以是O(k)。

# 扩展
## 扩展

大家貌似对单调队列 都有一些疑惑,首先要明确的是,题解中单调队列里的pop和push接口,仅适用于本题哈。单调队列不是一成不变的,而是不同场景不同写法,总之要保证队列里单调递减或递增的原则,所以叫做单调队列。 不要以为本题中的单调队列实现就是固定的写法哈。

大家貌似对deque也有一些疑惑,C++中deque是stack和queue默认的底层实现容器(这个我们之前已经讲过啦),deque是可以两边扩展的,而且deque里元素并不是严格的连续分布的。



# 其他语言版本
## 其他语言版本

### Java:

Java:
```Java
//解法一
//自定义数组
Expand Down Expand Up @@ -298,7 +298,8 @@ class Solution {
}
```

Python:
### Python:

```python
from collections import deque

Expand Down Expand Up @@ -338,8 +339,7 @@ class Solution:
return result
```


Go:
### Go:

```go
// 封装单调队列的方式解题
Expand Down Expand Up @@ -401,7 +401,8 @@ func maxSlidingWindow(nums []int, k int) []int {
}
```

Javascript:
### Javascript:

```javascript
/**
* @param {number[]} nums
Expand Down Expand Up @@ -449,7 +450,7 @@ var maxSlidingWindow = function (nums, k) {
};
```

TypeScript:
### TypeScript:

```typescript
function maxSlidingWindow(nums: number[], k: number): number[] {
Expand Down Expand Up @@ -497,7 +498,9 @@ function maxSlidingWindow(nums: number[], k: number): number[] {
};
```

Swift:
### Swift:

解法一:

```Swift
/// 双向链表
Expand Down Expand Up @@ -638,7 +641,8 @@ func maxSlidingWindow(_ nums: [Int], _ k: Int) -> [Int] {
return result
}
```
Scala:
### Scala:

```scala
import scala.collection.mutable.ArrayBuffer
object Solution {
Expand Down Expand Up @@ -686,8 +690,8 @@ class MyQueue {
}
```

### PHP:

PHP:
```php
class Solution {
/**
Expand Down Expand Up @@ -764,7 +768,8 @@ class MyQueue{
}
```

C#:
### C#:

```csharp
class myDequeue{
private LinkedList<int> linkedList = new LinkedList<int>();
Expand Down Expand Up @@ -805,7 +810,7 @@ class myDequeue{
}
```

rust:
### Rust:

```rust
impl Solution {
Expand Down

AltStyle によって変換されたページ (->オリジナル) /