Skip to content

Instantly share code, notes, and snippets.

Jovian Lin jovianlin

Block or report user

Report or block jovianlin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jovianlin
jovianlin / Trie
Created Mar 20, 2019
Trie Python
View Trie
#!/usr/bin/env python
class Node( object ):
def __init__( self, end_node = False ):
self.end_node = end_node
self.prefix_count = 0
self.children = {}
View LeetCode_JumpGameII.py
class Solution:
def jump(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums or len(nums) == 1:
return 0
@jovianlin
jovianlin / daily_coding_problem_57.py
Created Jan 14, 2019
Daily Coding Problem: Problem #57
View daily_coding_problem_57.py
"""
Good morning! Here's your coding interview problem for today.
This problem was asked by Amazon.
Given a string s and an integer k, break up the string into multiple texts such that each text has a length of k or less.
You must break it up so that words don't break across lines. If there's no way to break the text up, then return null.
You can assume that there are no spaces at the ends of the string and that there is exactly one space between each word.
@jovianlin
jovianlin / n-queens-ii.py
Created Jan 4, 2019
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.
View n-queens-ii.py
class Solution(object):
def totalNQueens(self, n):
"""
:type n: int
:rtype: int
"""
positions = [None]*n
_, count = self.solve(n, 0, positions, count=0)
return count
@jovianlin
jovianlin / MinHeap_and_MaxHeap.py
Created Dec 21, 2018
Python3 MinHeap and MaxHeap
View MinHeap_and_MaxHeap.py
class MaxHeapObj:
def __init__(self,val): self.val = val
def __lt__(self,other): return self.val > other.val
def __eq__(self,other): return self.val == other.val
def __str__(self): return str(self.val)
class MinHeap:
def __init__(self): self.h = []
def heappush(self,x): heapq.heappush(self.h,x)
def heappop(self): return heapq.heappop(self.h)
View LeetCode_KthSmallestElementBST.py
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def kthSmallest(self, root, k):
"""
@jovianlin
jovianlin / LeetCode_RemoveNthNodeFromEndList.py
Created Dec 14, 2018
Remove Nth Node From End of List (in one pass)
View LeetCode_RemoveNthNodeFromEndList.py
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def removeNthFromEnd(self, head, k):
"""
:type head: ListNode
View LeetCode_BackspaceStringCompare.py
class Solution:
def backspaceCompare(self, S, T):
"""
:type S: str
:type T: str
:rtype: bool
"""
pointerS, pointerT = len(S)-1, len(T)-1
skipS, skipT = 0, 0
View LeetCode_IntersectionofTwoLinkedLists.py
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def getLength(self, node):
length = 0
while node:
View LeetCode_Replace Words_TRIE.py
class TrieNode:
def __init__(self):
self.children = {}
self.isWord = False
class WordDictionary:
def __init__(self):
self.root = TrieNode()
You can’t perform that action at this time.