Skip to content

Commit bb9fbe4

Browse files
authored
Create Design a Stack With Increment Operation.py
1 parent 89b7420 commit bb9fbe4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class CustomStack:
2+
3+
def __init__(self, maxSize: int):
4+
self.size = maxSize
5+
self.stack = []
6+
7+
def push(self, x: int) -> None:
8+
if len(self.stack) < self.size:
9+
self.stack.append(x)
10+
11+
def pop(self) -> int:
12+
return self.stack.pop() if len(self.stack) > 0 else -1
13+
14+
def increment(self, k: int, val: int) -> None:
15+
l = k if len(self.stack) > k else len(self.stack)
16+
for i in range(l):
17+
self.stack[i] += val

0 commit comments

Comments
 (0)