Skip to content

Instantly share code, notes, and snippets.

View Henryhehe's full-sized avatar

Henry Henryhehe

  • Toronto
View GitHub Profile
@Henryhehe
Henryhehe / graph.py
Created October 11, 2018 22:58
Graph Questions
# Course Schedule
class Solution:
#Finding cycle exits in a directed graph
def canFinish(self, numCourses, prerequisites):
graph = [[] for _ in range(numCourses)]
visit = [0 for _ in range(numCourses)]
for x, y in prerequisites:
graph[x].append(y)
def dfs(i):
@Henryhehe
Henryhehe / LinkedList.py
Created October 11, 2018 22:23
List question set
#142 Linked List Cycle II
class Solution(object):
def detectCycle(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if not head:
return None
slow = fast = head
@Henryhehe
Henryhehe / stack_queue.py
Created October 4, 2018 03:06
Stack and queue
#Min stack
class MinStack:
def __init__(self):
"""
initialize your data structure here.
"""
self.stack = []
def push(self, x):
@Henryhehe
Henryhehe / Tree.py
Created October 4, 2018 03:03
Tree
#Same Tree
class Solution:
def isSameTree(self, p, q):
"""
:type p: TreeNode
:type q: TreeNode
:rtype: bool
"""
result = self.isSame(p,q)
return result
class Solution:
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if not matrix or not matrix[0]:
return False
row,col = len(matrix),len(matrix[0])
class Solution:
def compareVersion(self, version1, version2):
"""
:type version1: str
:type version2: str
:rtype: int
"""
version1 = version1.split(".")
version2 = version2.split(".")
longer_length = max(len(version1),len(version2))
@Henryhehe
Henryhehe / gist:2c6eb9a1ffcbc5e29596073dea9db39f
Created September 27, 2018 04:48
Search in Rotated Sorted Array
import math
class Solution:
def search(self,nums,target):
low = 0
high = len(nums) - 1
while low <=high:
mid = math.floor((low+high)/2)
if target == nums[mid]:
return mid
@Henryhehe
Henryhehe / GAME_MASTER_v0_1.protobuf
Created July 17, 2016 23:27 — forked from anonymous/GAME_MASTER_v0_1.protobuf
Pokemon Go decoded GAME_MASTER protobuf file v0.1
Result: 1
Items {
TemplateId: "BADGE_BATTLE_ATTACK_WON"
Badge {
BadgeType: BADGE_BATTLE_ATTACK_WON
BadgeRanks: 4
Targets: "\nd\350\007"
}
}
Items {