Question
Design a stack which supports the following operations.
Implement the CustomStack class:
CustomStack(int maxSize)Initializes the object withmaxSizewhich is the maximum number of elements in the stack or do nothing if the stack reached themaxSize.void push(int x)Addsxto the top of the stack if the stack hasn’t reached themaxSize.int pop()Pops and returns the top of stack or -1 if the stack is empty.void inc(int k, int val)Increments the bottomkelements of the stack byval. If there are less thankelements in the stack, just increment all the elements in the stack.
https://leetcode.com/problems/design-a-stack-with-increment-operation/
1 | class CustomStack { |