forked from super30admin/PreCourse-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise_1.py
More file actions
39 lines (30 loc) · 923 Bytes
/
Exercise_1.py
File metadata and controls
39 lines (30 loc) · 923 Bytes
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
class myStack:
#Please read sample.java file before starting.
#Kindly include Time and Space complexity at top of each file
#// Time Complexity : O(1)
#// Space Complexity : O(n)
#// Did this code successfully run on Leetcode : Yes
#// Any problem you faced while coding this : No
def __init__(self):
self.items = []
def isEmpty(self):
return len(self.items) == 0
def push(self, item):
self.items.append(item)
def pop(self):
if not self.isEmpty():
return self.items.pop()
else:
return "List is empty"
def peek(self):
if not self.isEmpty():
return self.items[-1]
def size(self):
return len(self.items)
def show(self):
return self.items
s = myStack()
s.push('1')
s.push('2')
print(s.pop())
print(s.show())