leetcode

package
v0.0.0-...-fd00836 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecreaseQueue

type DecreaseQueue[T constraints.Ordered] struct {
	// contains filtered or unexported fields
}

单调递减队列,头部始终是最大值

func NewDecreaseQueue

func NewDecreaseQueue[T constraints.Ordered]() *DecreaseQueue[T]

func (*DecreaseQueue[T]) Back

func (q *DecreaseQueue[T]) Back() T

func (*DecreaseQueue[T]) Empty

func (q *DecreaseQueue[T]) Empty() bool

func (*DecreaseQueue[T]) Front

func (q *DecreaseQueue[T]) Front() T

func (*DecreaseQueue[T]) Pop

func (q *DecreaseQueue[T]) Pop(val T)

单调队列,pop传入一个值比较

func (*DecreaseQueue[T]) Push

func (q *DecreaseQueue[T]) Push(val T)

func (*DecreaseQueue[T]) Size

func (q *DecreaseQueue[T]) Size() int

type IHeap

type IHeap [][2]int

使用go语言官方提供的接口实现小顶堆 用堆的好处是,如果使用快排,那么必须维护一样大小的数组 用堆,只用维护k大小的堆。(leetcode上不如快排快,可能是堆里面Pop和Push操作里面数组赋值太耗时。。。) 用小顶堆,维护k大小的堆,每次取出的是最小的,因此保留的都是更大的。

func (IHeap) Len

func (h IHeap) Len() int

func (IHeap) Less

func (h IHeap) Less(i, j int) bool

func (*IHeap) Pop

func (h *IHeap) Pop() any

func (*IHeap) Push

func (h *IHeap) Push(x any)

func (IHeap) Swap

func (h IHeap) Swap(i, j int)

type MyStack

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

func Constructor

func Constructor() MyStack

func (*MyStack) Empty

func (this *MyStack) Empty() bool

func (*MyStack) Pop

func (this *MyStack) Pop() int

func (*MyStack) Push

func (this *MyStack) Push(x int)

func (*MyStack) Top

func (this *MyStack) Top() int

Jump to

Keyboard shortcuts

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