当前位置:网站首页>Leetcode 1381. Design a stack that supports incremental operations
Leetcode 1381. Design a stack that supports incremental operations
2022-06-27 20:43:00 【I am fat tiger】
Title
1381. Design a stack supporting incremental operation
Topic link
https://leetcode-cn.com/problems/design-a-stack-with-increment-operation/
Topic ideas
Python3 Simulating stack operations with arrays ( The first in, the second out )
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
Complexity analysis
- Time complexity : O(N)
- Spatial complexity : O(1)
边栏推荐
- 云原生安全指南: 从零开始学 Kubernetes 攻防
- 优维HyperInsight:掘金164.94亿美元可观测市场的“金锄头”?
- Data intelligence enters the "deep water area", and data governance is the key
- 本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
- DBeaver恢复和备份数据库的方式
- Recommended practice sharing of Zhilian recruitment based on Nebula graph
- 智联招聘的基于 Nebula Graph 的推荐实践分享
- BAIC makes a brand new pickup truck, which is safe and comfortable
- Csdn Skills Tree use Experience and Product Analysis (1)
- SQL报了一个不常见的错误,让新来的实习生懵了
猜你喜欢
![[STL programming] [common competition] [Part 3]](/img/15/0c397d74128268e17897615ad1c84e.png)
[STL programming] [common competition] [Part 3]

Redis集群

【STL编程】【竞赛常用】【part 1】

Character interception triplets of data warehouse: substrb, substr, substring

Grasp the detailed procedure of function call stack from instruction reading

No wonder people chose apifox instead of postman

Cloud native Security Guide: learn kubernetes attack and defense from scratch
![[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.](/img/2a/da8e998cb4e89d655f3c4116316925.png)
[bug] Lenovo Xiaoxin has a problem. Your pin is unavailable.
![[STL programming] [common competition] [Part 2]](/img/67/2a2d787680c0984f6c294a9ec3355b.png)
[STL programming] [common competition] [Part 2]

Bit. Store: long bear market, stable stacking products may become the main theme
随机推荐
NVIDIA three piece environment configuration
Question brushing notes - tree (easy) - updating
Mongodb introduction and typical application scenarios
主键选择选择自增还是序列?
Database lock problem
Logcli-loki 命令行工具
Massive data attended the Lanzhou opengauss meetup (ECOLOGICAL NATIONAL trip) activity, enabling users to upgrade their applications with enterprise level databases
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
Recommended practice sharing of Zhilian recruitment based on Nebula graph
On the drawing skills of my writing career
Redis cluster
Csdn Skills Tree use Experience and Product Analysis (1)
花了6个月时间完成本科优秀毕业设计,我做了什么?
Installing services for NFS
How to reduce the weight transfer of unnecessary pages that users pay attention to?
Cloud native Security Guide: learn kubernetes attack and defense from scratch
Cocoscreator plays audio and synchronizes progress
Rust advanced ownership - memory management
最佳实践:优化Postgres查询性能(下)
Practice of combining rook CEPH and rainbow, a cloud native storage solution