-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathExercise_1.py
More file actions
52 lines (39 loc) · 1.19 KB
/
Copy pathExercise_1.py
File metadata and controls
52 lines (39 loc) · 1.19 KB
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
43
44
45
46
47
48
49
50
51
52
# Time Complexity : O(1)
# Space Complexity : O(1)
# Did this code successfully run on Leetcode : yes
# Any problem you faced while coding this : No
# Your code here along with comments explaining your approach
class myStack:
#Please read sample.java file before starting.
#Kindly include Time and Space complexity at top of each file
def __init__(self):
self.arr = list()
def isEmpty(self):
return self.size() == 0
def push(self, item):
self.arr.append(item)
def pop(self):
if self.isEmpty():
return "Stack is Empty"
return self.arr.pop()
def peek(self):
if self.isEmpty():
return "Stack is Empty"
return self.arr[-1]
def size(self):
return len(self.arr)
def show(self):
return self.arr
s = myStack()
print("Push: 1")
s.push('1')
print("Push: 2")
s.push('2')
print("Show: ",s.show())
print("isEmpty: ",s.isEmpty())
print("Pop: ",s.pop())
print("Show: ",s.show())
print("Pop: ",s.pop())
print("Show: ",s.show())
print("isEmpty: ",s.isEmpty())
print("Pop: ",s.pop())