Created
January 21, 2019 20:08
-
-
Save xuhang57/56d548c50929d552e6552d5e1fd109e2 to your computer and use it in GitHub Desktop.
Basic Data Structure in Python (Interview)
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
# 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