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

design 2 #2158

Open
wants to merge 2 commits 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
57 changes: 57 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class MyHashSet:

def __init__(self):
self.b=1000
self.bi= 1000
self.s = [None]*self.b

def hash1(self, key:int) -> int:
return key%self.b

def hash2(self, key:int) -> int:
return key//self.bi

def add(self, key: int) -> None:
a = self.hash1(key)
b = self.hash2(key)
if self.s[a] is None:
if a == 0:
self.s[a] = [False] * (self.bi+1)
else:
self.s[a] = [False] * self.bi

self.s[a][b] = True

def remove(self, key: int) -> None:
a = self.hash1(key)
b = self.hash2(key)
if self.s[a]== None:
return
self.s[a][b]= False

def contains(self, key: int) -> bool:
a = self.hash1(key)
b = self.hash2(key)
if self.s[a]== None:
return False
return self.s[a][b]









# Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)

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

def __init__(self):
self.min = int(sys.maxsize)
self.m=[]
self.s=[]
self.m.append(self.min)


def push(self, val: int) -> None:
if val< self.min:
self.min=val
self.m.append(self.min)
self.s.append(val)

def pop(self) -> None:
self.s.pop()
self.m.pop()
self.min=self.m[-1]

def top(self) -> int:
return self.s[-1]

def getMin(self) -> int:
return self.min


# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(val)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()