当前位置:网站首页>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)
边栏推荐
- Vs code runs "yarn run dev" and reports "yarn": the file XXX cannot be loaded
- 流程判断-三目运算-for循环
- Informatics Orsay all in one 1335: [example 2-4] connected block
- 你知道 log4j2 各项配置的全部含义吗?带你了解 log4j2 的全部组件
- 金源高端IPO被终止:曾拟募资7.5亿 儒杉资产与溧阳产投是股东
- 中金证券经理给的开户二维码安全吗?找谁可以开户啊?
- 在线文本按行批量反转工具
- 【建议收藏】ABAP随笔-EXCEL-4-批量导入-推荐
- labelimg使用指南
- redis集群系列二
猜你喜欢

基于STM32F103ZET6库函数外部中断实验

The IPO of Yuchen Airlines was terminated: Guozheng was proposed to raise 500million yuan as the major shareholder

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

基于STM32F103ZET6库函数蜂鸣器实验

爬取国家法律法规数据库

Bit.Store:熊市漫漫,稳定Staking产品或成主旋律

VS code 运行yarn run dev 报yarn : 无法加载文件XXX的问题

海底电缆探测技术总结

实战回忆录:从Webshell开始突破边界

《第五项修炼》(The Fifth Discipline):学习型组织的艺术与实践
随机推荐
Comment encapsuler un appel à une bibliothèque
Minmei new energy rushes to Shenzhen Stock Exchange: the annual accounts receivable exceeds 600million and the proposed fund-raising is 450million
Market status and development prospect forecast of global handheld ventilator industry in 2022
Market status and development prospect forecast of global tetramethylammonium hydroxide developer industry in 2022
工作流自动化 低代码是关键
Mathematical derivation from perceptron to feedforward neural network
Market status and development prospect forecast of the global shuttleless air jet loom industry in 2022
1023 Have Fun with Numbers
新中大冲刺科创板:年营收2.84亿 拟募资5.57亿
Solution of adding st-link to Huada MCU Keil
2022年第一季度消费金融APP用户洞察——总数达4479万人
中金证券经理给的开户二维码安全吗?找谁可以开户啊?
图扑数字孪生智慧能源一体化管控平台
OpenSSL client programming: SSL session failure caused by an obscure function
使用MySqlBulkLoader批量插入数据
binder hwbinder vndbinder
Labelimg usage guide
Jinyuan's high-end IPO was terminated: it was planned to raise 750million Rushan assets and Liyang industrial investment were shareholders
【云驻共创】高校数字化差旅建设“解决之道”
(LC)46. 全排列