Skip to content
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
7 changes: 0 additions & 7 deletions Sample.java

This file was deleted.

38 changes: 38 additions & 0 deletions design_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Time Complexity : O(1)
#Space Complexity : O(10^6)
#Did this code successfully run on Leetcode :Yes
class MyHashSet(object):

def __init__(self):
self.num_of_buckets = 1000
self.buckets = [None] * self.num_of_buckets

def get_primary_hash(self, key):
return key % self.num_of_buckets

def get_secondary_hash(self, key):
return key // self.num_of_buckets

def add(self, key):
first_hash = self.get_primary_hash(key)
if self.buckets[first_hash] == None:
if first_hash == 0:
self.buckets[first_hash] = [False] * (self.num_of_buckets + 1)
else:
self.buckets[first_hash] = [False] * (self.num_of_buckets)
second_hash = self.get_secondary_hash(key)
self.buckets[first_hash][second_hash] = True

def remove(self, key):
first_hash = self.get_primary_hash(key)
second_hash = self.get_secondary_hash(key)
if self.buckets[first_hash] != None:
self.buckets[first_hash][second_hash] = False

def contains(self, key):
first_hash = self.get_primary_hash(key)
second_hash = self.get_secondary_hash(key)
if self.buckets[first_hash] != None:
if self.buckets[first_hash][second_hash] == True:
return True
return False
26 changes: 26 additions & 0 deletions problem-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# TC = O(1)
# SC = O(n)
class MinStack(object):

def __init__(self):
self.st=[]
self.min_st = []
self.min = float('inf')

def push(self, value):
if self.min >= value:
self.min_st.append(self.min)
self.min = value
self.st.append(value)


def pop(self):
if (self.st.pop() == self.min):
self.min = self.min_st.pop()

def top(self):
return self.st[-1]

def getMin(self):
return self.min