t_046_239_sliding_window_maximum

package
v0.0.0-...-bdaad32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

README

https://leetcode.cn/problems/sliding-window-maximum/
239. 滑动窗口最大值
困难

给你一个整数数组 nums,有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。

返回 滑动窗口中的最大值 。

 

示例 1:

输入:nums = [1,3,-1,-3,5,3,6,7], k = 3
输出:[3,3,5,5,6,7]
解释:
滑动窗口的位置                最大值
---------------               -----
[1  3  -1] -3  5  3  6  7       3
 1 [3  -1  -3] 5  3  6  7       3
 1  3 [-1  -3  5] 3  6  7       5
 1  3  -1 [-3  5  3] 6  7       5
 1  3  -1  -3 [5  3  6] 7       6
 1  3  -1  -3  5 [3  6  7]      7

示例 2:

输入:nums = [1], k = 1
输出:[1]

 

提示:

    1 <= nums.length <= 105
    -104 <= nums[i] <= 104
    1 <= k <= nums.length


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MyQueue

type MyQueue struct {
	// contains filtered or unexported fields
}

单调队列

func NewMyQueue

func NewMyQueue() MyQueue

func (*MyQueue) Empty

func (m *MyQueue) Empty() bool

func (*MyQueue) GetBackVal

func (m *MyQueue) GetBackVal() (n int)

func (*MyQueue) GetFrontVal

func (m *MyQueue) GetFrontVal() (n int)

func (*MyQueue) GetMaxVal

func (m *MyQueue) GetMaxVal() int

func (*MyQueue) Pop

func (m *MyQueue) Pop(n int)

func (*MyQueue) PopBack

func (m *MyQueue) PopBack()

func (*MyQueue) PopFront

func (m *MyQueue) PopFront()

func (*MyQueue) Push

func (m *MyQueue) Push(n int)

func (*MyQueue) PushBack

func (m *MyQueue) PushBack(n int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL