Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.4 KB

_1381. Design a Stack With Increment Operation.md

File metadata and controls

60 lines (42 loc) · 1.4 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 06, 2024

Last updated : July 06, 2024


Related Topics : Array, Stack, Design

Acceptance Rate : 80.59 %


This question has the honour of being my 400th question on LeetCode.

On Day 39 of my grind, 8:35PM PST, this question was done. Simple one to end off this sprint. :)


Solutions

Python

class CustomStack:

    def __init__(self, maxSize: int):
        self.stk = []
        self.maxx = maxSize

    def push(self, x: int) -> None:
        if len(self.stk) >= self.maxx :
            return
        self.stk.append(x)

    def pop(self) -> int:
        if not self.stk :
            return -1
        return self.stk.pop()

    def increment(self, k: int, val: int) -> None:
        for i in range(min(k, len(self.stk))) :
            self.stk[i] += val


# Your CustomStack object will be instantiated and called as such:
# obj = CustomStack(maxSize)
# obj.push(x)
# param_2 = obj.pop()
# obj.increment(k,val)