-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.py
42 lines (30 loc) · 864 Bytes
/
stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# coding=gbk
from typing import List
class MyStack:
'''
helper class
'''
_stack: List
def __init__(self):
'''
Constructor
'''
self._stack = []
def push(self, input1):
self._stack.append(input1)
print("ÍÆÈë " + str(input1))
def pop(self):
self._stack.pop()
def isEmpty(self) -> bool:
return len(self._stack) == 0
def checkIn(self, input1) -> bool:
if self.isEmpty():
return False
return input1 // 10 in self._stack
def checkGap(self, input1) -> int:
if self.isEmpty():
return False
return len(self._stack) - 1 - self._stack.index(input1 // 10)
def checkClear(self):
if len(self._stack) > 50:
self._stack.clear()