This file contains hidden or 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 TrieNode: | |
def __init__(self): | |
self.next = [None] * 26 | |
self.word = None | |
class Solution: | |
def findWords(self, board, words): | |
""" | |
:type board: List[List[str]] | |
:type words: List[str] |
This file contains hidden or 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 Solution: | |
def findWords(self, board, words): | |
""" | |
:type board: List[List[str]] | |
:type words: List[str] | |
:rtype: List[str] | |
""" | |
for i in range(len(board)): | |
for j in range(len(board[0])): |
This file contains hidden or 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
import re | |
class Solution(object): | |
def fractionAddition(self, expression): | |
""" | |
:type expression: str | |
:rtype: str | |
""" | |
signs = list() | |
if expression[0] != "-": |
This file contains hidden or 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 Solution(object): | |
def maxCount(self, m, n, ops): | |
""" | |
:type m: int | |
:type n: int | |
:type ops: List[List[int]] | |
:rtype: int | |
""" | |
for i, j in ops: | |
m = min(m, i) |
This file contains hidden or 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 Solution(object): | |
def change(self, amount, coins): | |
""" | |
:type amount: int | |
:type coins: List[int] | |
:rtype: int | |
""" | |
# dp placeholder | |
dp = [0] * (amount+1) | |
dp[0] = 1 |
This file contains hidden or 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 Solution(object): | |
# O(n) O(n) | |
def coinChange(self, coins, amount): | |
""" | |
:type coins: List[int] | |
:type amount: int | |
:rtype: int | |
""" | |
# corner case | |
if not coins: |
This file contains hidden or 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 Solution(object): | |
def trap(self, height): | |
""" | |
:type height: List[int] | |
:rtype: int | |
""" | |
# return placeholder | |
res = 0 | |
# corner case |
This file contains hidden or 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 NestedIterator(object): | |
def __init__(self, nestedList): | |
""" | |
Initialize your data structure here. | |
:type nestedList: List[NestedInteger] | |
""" | |
def gen(nestedList): | |
for x in nestedList: | |
if x.isInteger(): |
This file contains hidden or 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 Solution(object): | |
def search(self, nums, target): | |
""" | |
:type nums: List[int] | |
:type target: int | |
:rtype: int | |
""" | |
# corner case: input is None or empty list | |
if not nums: | |
return -1 |
This file contains hidden or 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
# BFS | |
class Solution(object): | |
def removeInvalidParentheses(self, s): | |
""" | |
:type s: str | |
:rtype: List[str] | |
""" | |
level = {s} | |
while True: | |
valid = filter(self.is_valid, level) |