当前位置:网站首页>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)
边栏推荐
- SQL Server - window function - solve the problem of filtering consecutive n records
- Select auto increment or sequence for primary key selection?
- CSDN skill tree experience and product analysis (1)
- 智联招聘的基于 Nebula Graph 的推荐实践分享
- 主键选择选择自增还是序列?
- BAIC makes a brand new pickup truck, which is safe and comfortable
- 数据库优化
- Batch insert data using MySQL bulkloader
- What is a low code development platform? Why is it so hot now?
- redis数据结构
猜你喜欢

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

Pfsense plus22.01 Chinese customized version release

键入网址到网页显示,期间发生了什么?

A distribution fission activity is more than just a circle of friends

Openharmony hisysevent dotting and calling practice of # Summer Challenge (L2)

Accumulating power in the middle stage, UFIDA IUAP builds a new base for digital intelligence of social enterprises

【精品必读】Linux系统Oracle数据库趣解子查询

实现字符串MyString

BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!
Record a failure caused by a custom redis distributed lock
随机推荐
pfSense Plus22.01中文定制版发布
数据库优化
Binary tree related problems 2
Logcli Loki command line tool
SQL审核平台权限模块介绍和账号创建教程
Redis集群
Postman 汉化教程(Postman中文版)
Mass lucky hash game system development - conflict resolution (code analysis)
【STL编程】【竞赛常用】【part 2】
BTC和ETH重新夺回失地!引领市场复苏?加密将步入“冰河时代”!
花了6个月时间完成本科优秀毕业设计,我做了什么?
Dictionary tree (review)
什么是堆栈?
Logcli-loki 命令行工具
Batch insert data using MySQL bulkloader
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
linux系统笑着玩Oracle数据库多表查询-连接查询
SQL audit platform permission module introduction and account creation tutorial
Linux system Oracle 19C OEM monitoring management
数据库事务