Skip to content

Instantly share code, notes, and snippets.

@xuhang57
Created January 21, 2019 20:08
Show Gist options
  • Save xuhang57/56d548c50929d552e6552d5e1fd109e2 to your computer and use it in GitHub Desktop.
Save xuhang57/56d548c50929d552e6552d5e1fd109e2 to your computer and use it in GitHub Desktop.
Basic Data Structure in Python (Interview)
# String
string = ""
# Tuple
t = tuple() # (), (1,)
# List (Array)
l = []
# Stack, LIFO
stack = []
# Queue, FIFO
queue = [] # or deque in collections
# Dictionary
dictionary = {} # dict()
# Set
s = set()
# Linked List
class ListNode(object):
def __init__(self, x):
self.val = x
self.next = None
head = ListNode(0) # ListNode(None)
# Binary Tree
class TreeNode(object):
def __init__(self, x):
self.val = x
self.left = None
self.right = None
root = TreeNode(1)
# Graph
class UndirectedGraphNode(object):
def __init__(self, x):
self.label = x
self.neighbors = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment