Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please review #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions HashSet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class MyHashSet(object):

def __init__(self):
"""
Initialize your data structure here.
"""
self.set=[0]*1000000

def add(self, key):
"""
:type key: int
:rtype: None
"""
self.set[key]=1

def remove(self, key):
"""
:type key: int
:rtype: None
"""

self.set[key]=0

def contains(self, key):
"""
Returns true if this set contains the specified element
:type key: int
:rtype: bool
"""
return self.set[key]==1


# Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)
58 changes: 58 additions & 0 deletions ImplementQueue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class MyQueue(object):

def __init__(self):
"""
Initialize your data structure here.
"""
self.stackin=[]
self.stackout=[]

def push(self, x):
"""
Push element x to the back of queue.
:type x: int
:rtype: None
"""
self.stackin.append(x)

def pop(self):
"""
Removes the element from in front of queue and returns that element.
:rtype: int
"""
if len(self.stackout)!=0:
return self.stackout.pop()
else:
while len(self.stackin)!=0:
self.stackout.append(self.stackin.pop())
return self.stackout.pop()

def peek(self):
"""
Get the front element.
:rtype: int
"""
if len(self.stackout)!=0:
return self.stackout[-1]
else:
while len(self.stackin)!=0:
self.stackout.append(self.stackin.pop())
return self.stackout[-1]

def empty(self):
"""
Returns whether the queue is empty.
:rtype: bool
"""
if len(self.stackin)==0 and len(self.stackout)==0:
return True
else:
return False


# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()