From e5560dc33a7c107364cbcfcab71c227cc2db7269 Mon Sep 17 00:00:00 2001 From: Daliparthy Sumukha Kavya <122427131+SumukhaKavya@users.noreply.github.com> Date: Wed, 1 Nov 2023 19:10:58 +0530 Subject: [PATCH] Update D21P1_LeetCode_1381.py --- Python Solutions/D21P1_LeetCode_1381.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Python Solutions/D21P1_LeetCode_1381.py b/Python Solutions/D21P1_LeetCode_1381.py index 8b3de34..7ed67da 100644 --- a/Python Solutions/D21P1_LeetCode_1381.py +++ b/Python Solutions/D21P1_LeetCode_1381.py @@ -1 +1,18 @@ -# Python3 code coming soon \ No newline at end of file +class CustomStack: + def __init__(self, maxSize: int): + self.maxSize = maxSize + self.stack = [] + + def push(self, x: int) -> None: + if len(self.stack) < self.maxSize: + self.stack.append(x) + + def pop(self) -> int: + if not self.stack: + return -1 + else: + return self.stack.pop() + + def increment(self, k: int, val: int) -> None: + for i in range(min(k,len(self.stack))): + self.stack[i] += val