Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

min stack in python

class MinStack:

    def __init__(self):
        self.stack=deque([])
        self.min=deque([])

    def push(self, val: int) -> None:
        self.stack.append(val)
        if len(self.min)==0 or val<self.min[-1]:
            self.min.append(val)
        else:
            self.min.append(self.min[-1])

    def pop(self) -> None:
        x=self.stack.pop()
        self.min.pop()
        return x

    def top(self) -> int:
        return self.stack[-1]

    def getMin(self) -> int:
        return self.min[-1]
Comment

PREVIOUS NEXT
Code Example
Python :: python should i use getters and setters 
Python :: how i get url value in get_queryset function in drf 
Python :: pyqt popup yes no 
Python :: List get both index and value. 
Python :: check if input is pandas dataframe 
Python :: Python NumPy ndarray.T Example to convert an array 
Python :: python requests cannot find existing url 
Python :: sorted set in python 
Python :: python raise exception with custom message 
Python :: better way to see full csv in jupyter notebook 
Python :: h2o dataframe columns drop 
Python :: add text to jpg python 
Python :: python clear memory 
Python :: bst deleting 
Python :: histogram relative frequency 
Python :: choice without replacement python 
Python :: how to format a file in python 
Python :: software developer tools list 
Python :: selenium session id python 
Python :: numpy concatenate arrays 
Python :: how to maximize the screen in selenium 
Python :: python identify image mode 
Python :: pdfs in django 
Python :: pass query params django template 
Python :: python sound 
Python :: input a number and print even numbers up to that number in python 
Python :: python one line key increment or add 
Python :: python download chromebook 
Python :: Passing array to methods 
Python :: python set terminal size 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =