This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(self, val): | |
self.val = val | |
self.left = None | |
self.right = None | |
def __lt__(self, val): | |
return self.val < val | |
def __gt__(self, val): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(self, val): | |
self.val = val | |
self.left = None | |
self.right = None | |
self.parent = None | |
def has_no_kids(self): | |
return self.right is None and self.left is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MaxPQ(object): | |
def __init__(self): | |
# TODO initialize with array | |
self._N = -1 | |
self._arr = [] | |
pass | |
def _compare(self, a, b): | |
if a > b: return 1 | |
if a < b: return -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from heapq import heappop, heappush, heapify | |
class Node: | |
def __init__(self, val): | |
self.val = val | |
self.next = None | |
def __str__(self): | |
return "<Node: %d>" % self.val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import shuffle | |
from time import time | |
def compare(a, b): | |
if a > b: return 1 | |
if a < b: return -1 | |
return 0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hashmap(object): | |
""" | |
character holding hash map | |
""" | |
def __init__(self, hash_fn, length=100): | |
assert hasattr(hash_fn, '__call__'), 'You must provide a hash function' | |
self._buckets = [None] * length | |
self.hash_len = length | |
self.hash_fn = hash_fn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
def is_left(a): | |
if a == '[' or a == '(' or a == '{': return True | |
return False | |
def is_right(a): | |
if a == ']' or a == '}' or a == ')': return True | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import choice | |
from copy import deepcopy | |
class MinCutGraph(object): | |
def __init__(self, create_graph_fn): | |
if not hasattr(create_graph_fn, '__call__'): | |
raise TypError('Expected `create_graph_fn` to be a func') | |
self.graph = create_graph_fn() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_circular(arr, start): | |
if not isinstance(arr, list): raise TypeError('Expected arr to be list') | |
if not isinstance(start, int): raise TypeError('Expected start to be int') | |
size = len(arr) | |
n = size | |
pos = start | |
# key running count to track that each index is hit | |
# use the index as the count, total_exp will be the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(object): | |
def __init__(self, key, parent=None): | |
self.key = key | |
self.parent = parent | |
self.left = None | |
self.right = None | |
def has_children(self): return len(self) > 0 | |
def delete(self, node): |
OlderNewer