Explain your approach in three sentences only at top of your code
Problem 1:(https://leetcode.com/problems/design-hashset/)
Design MinStack (https://leetcode.com/problems/min-stack/)
Explain your approach in three sentences only at top of your code
Design MinStack (https://leetcode.com/problems/min-stack/)
'''
Method to Implement Hashset
'''
class MyHashSet:
def __init__(self):
self.keyRange = 769
self.bucketArray = [Bucket() for i in range(self.keyRange)]
def _hash(self, key):
return key%self.keyRange
def add(self,key):
bucketindex = self._hash(key)
self.bucketArray[bucketindex].insert(key)
def remove(self, key):
bucketindex = self._hash(key)
self.bucketArray[bucketindex].delete(key)
def contains(self,key):
bucketIndex = self._hash(key)
self.bucketArray[bucketIndex].exists(key)
class Node:
def __init__(self, val, nextnode=None):
self.val = val
self.nextnode = nextnode
class Bucket:
def __init__(self):
self.head = Node(0)
def add(self, newValue):
if not self.exists(newValue):
newNode = Node(newValue, self.head.next)
self.head.next = newNode
def delete(self, val):
prev = self.head
curr = self.head.next
while curr:
if curr.val==val:
prev.nextnode = curr.nextnode
return
prev = curr
curr = curr.nextnode
def exists(self,val):
curr = self.head.nextnode
while curr:
if curr.val==val:
return True
curr = curr.nextnode
return False
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.