当前位置:网站首页>Leetcode 1381. 设计一个支持增量操作的栈
Leetcode 1381. 设计一个支持增量操作的栈
2022-06-27 17:57:00 【我是胖虎啊】
题目名称
1381. 设计一个支持增量操作的栈
题目链接
https://leetcode-cn.com/problems/design-a-stack-with-increment-operation/
题目思路
Python3用数组模拟栈操作(先进后出的特点)
code for Python3
class CustomStack:
def __init__(self, maxSize: int):
self.arr = []
self.maxSize = maxSize
def push(self, x: int) -> None:
if len(self.arr) < maxSize:
self.arr.append(x)
def pop(self) -> int:
if self.arr:
return self.arr.pop()
else:
return -1
def increment(self, k: int, val: int) -> None:
if not self.arr:
return
elif len(self.arr) <= k:
for i in range(len(self.arr)):
self.arr[i] += val
else:
for i in range(k):
self.arr[i] += val
复杂度分析
- 时间复杂度: O(N)
- 空间复杂度: O(1)
边栏推荐
- Solution to Maxwell error (MySQL 8.x connection)
- NVIDIA Clara-AGX-Developer-Kit installation
- CDGA|交通行业做好数字化转型的核心是什么?
- Function key input experiment based on stm32f103zet6 Library
- 1028 List Sorting
- 谈谈线程安全
- 昱琛航空IPO被终止:曾拟募资5亿 郭峥为大股东
- Error reported by Huada MCU Keil_ Weak's solution
- Introduction to deep learning and neural networks
- labelimg使用指南
猜你喜欢
Minmei new energy rushes to Shenzhen Stock Exchange: the annual accounts receivable exceeds 600million and the proposed fund-raising is 450million
深度学习和神经网络的介绍
【登录界面】
华大单片机KEIL添加ST-LINK解决方法
新中大冲刺科创板:年营收2.84亿 拟募资5.57亿
Online text batch inversion by line tool
Comprehensively analyze the zero knowledge proof: resolve the expansion problem and redefine "privacy security"
数组练习 后续补充
昱琛航空IPO被终止:曾拟募资5亿 郭峥为大股东
“我让这个世界更酷”2022华清远见研发产品发布会圆满成功
随机推荐
The IPO of Yuchen Airlines was terminated: Guozheng was proposed to raise 500million yuan as the major shareholder
On thread safety
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
深度学习和神经网络的介绍
驾驭一切的垃圾收集器 -- G1
DCC888 :Register Allocation
One to one relationship
shell脚本常用命令(三)
Don't worry. This is the truth about wages in all industries in China
Market status and development prospect forecast of the global infusion needle less connector industry in 2022
2022年第一季度消费金融APP用户洞察——总数达4479万人
International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding
可靠的分布式锁 RedLock 与 redisson 的实现
Core dynamic Lianke rushes to the scientific innovation board: with an annual revenue of 170million yuan, Beifang Electronics Institute and Zhongcheng venture capital are shareholders
shell脚本常用命令(四)
实战回忆录:从Webshell开始突破边界
binder hwbinder vndbinder
[cloud based co creation] the "solution" of Digital Travel construction in Colleges and Universities
Redis 原理 - String
如何封裝調用一個庫