Download 10-week-algorithm-excercise-master/Week_01/155/min_stack.py from Dorothydu/gitrepo_20: direct link, hf CLI and curl.
- Browser
- Download file 576 Bytes
-
https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/Week_01/155/min_stack.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_20/10-week-algorithm-excercise-master/Week_01/155/min_stack.py
-
curl -L -o min_stack.py https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/Week_01/155/min_stack.py
576 Bytes
| class MinStack: | |
| def __init__(self): | |
| """ | |
| initialize your data structure here. | |
| """ | |
| self.stack = [] | |
| self.min_stack = [] | |
| def push(self, x: int) -> None: | |
| self.stack.append(x) | |
| if len(self.min_stack) == 0 or self.min_stack[-1] >= x: | |
| self.min_stack.append(x) | |
| def pop(self) -> None: | |
| v = self.stack.pop() | |
| if v == self.min_stack[-1]: | |
| self.min_stack.pop() | |
| def top(self) -> int: | |
| return self.stack[-1] | |
| def getMin(self) -> int: | |
| return self.min_stack[-1] | |