当前位置:网站首页>Leetcode: sword finger offer 59 - ii Maximum value of queue [deque + sortedlist]
Leetcode: sword finger offer 59 - ii Maximum value of queue [deque + sortedlist]
2022-06-11 18:47:00 【Review of the white speed Dragon King】

analysis
Whatever it is o1
Just pick it up sortedlist + deque Simulation is enough
ac code
from sortedcontainers import SortedList
class MaxQueue:
def __init__(self):
self.lst = SortedList()
self.q = deque([])
def max_value(self) -> int:
if not self.q: return -1
return self.lst[-1]
def push_back(self, value: int) -> None:
self.q.append(value)
self.lst.add(value)
def pop_front(self) -> int:
if not self.q: return -1
val = self.q.popleft()
self.lst.remove(val)
return val
# Your MaxQueue object will be instantiated and called as such:
# obj = MaxQueue()
# param_1 = obj.max_value()
# obj.push_back(value)
# param_3 = obj.pop_front()
summary
deque and sortedlist Investigate
边栏推荐
- Niu Ke's questions -- two sorting methods
- 基于TI AM5728 + Artix-7 FPGA开发板(DSP+ARM) 5G通信测试手册
- uni-app 慕客热搜项目实战(一)tabBar的制作
- 2022-2023 MEM pre approval interview notice of School of management, Xi'an Jiaotong University
- 牛客刷题——part8
- 全志科技T3开发板(4核ARM Cortex-A7)——MQTT通信协议案例
- 北京邮电大学2023级工商管理硕士MBA(非全日制)已开启
- Undefined reference to 'g2o:: vertexe3:: vertexe3()'
- SQL注入漏洞学习之一:phpstudy集成环境搭建DVWA靶场
- 今天睡眠质量记录60分
猜你喜欢

Non recursive traversal of binary tree

The 2023 MBA (Part-time) of Beijing University of Posts and telecommunications has been launched

牛客刷题——两种排序方法

牛客刷题——把字符串转换成整数

2022-2023 MEM pre approval interview notice of School of management, Xi'an Jiaotong University

Niu Ke swipes the question -- converting a string to an integer

*Jetpack notes understanding of lifecycle ViewModel and livedata
Complete in-depth learning of MySQL from 0 to 1 -- phase 2 -- basics

Gmail:如何撤回发出的邮件?

Cool visualization tool: first introduction to processing
随机推荐
Financial bank_ Introduction to collection system
SQL injection vulnerability learning 1: phpstudy integrated environment building DVWA shooting range
Visual slam lecture notes-10-2
cf:A. Print a Pedestal (Codeforces logo?)【简单遍历模拟】
公共字段自动填充,你了解吗
记录一下phpstudy配置php8.0和php8.1扩展redis
牛客刷题——不要二
Map and set
信号的处理与捕捉
Add your favorite background music
The 2023 MBA (Part-time) of Beijing University of Posts and telecommunications has been launched
Force deduction 32 questions longest valid bracket
Labelme for image data annotation
Analysis of runtime instantiation of XML view root node in SAP ui5
KMP! You deserve it!!! Run directly!
Function development of user information management
平衡搜索二叉树——AVL树
cf:G. Count the Trains【sortedset + bisect + 模拟维持严格递减序列】
Non recursive traversal of binary tree
BottomSheetDialog 使用详解,设置圆角、固定高度、默认全屏等