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
{"lastUpload":"2020-03-25T18:30:15.275Z","extensionVersion":"v3.4.3"} |
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
# 1004: Max ConsecutiveOnes III | |
maxLength = 0 | |
numZeros = 0 | |
# 1052: Grumpy Bookstore Owner | |
maxCustWhenGrumpy = 0 | |
idxOfStartX = 0 | |
custWhenGrumpy = 0 | |
# 1456: Max Number of Vowels in Substring of given length |
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
Interval Operations | |
There are a few operations that can be performed on intervals: | |
1. Merge interval[] s.t. the all intervals are disjoint. | |
[0,5],[5,7] ==> [0,7] | |
2. Insert interval into interval[] s.t. all intervals are disjoint. | |
3. Find intersection between two interval[]. | |
[0,5],[5,7] => [5,5] | |
In order to perform these operations, it is important to understand the 6 |
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
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, val=0, left=None, right=None): | |
# self.val = val | |
# self.left = left | |
# self.right = right | |
class Solution: | |
''' | |
left subtree needs to be balanced | |
right subtree needs to be balanced |
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
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, val=0, left=None, right=None): | |
# self.val = val | |
# self.left = left | |
# self.right = right | |
class Solution: | |
def flatten(self, root: TreeNode) -> None: | |
""" | |
Do not return anything, modify root in-place instead. |
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
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution: | |
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode': | |
''' |
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
# Definition for a binary tree node. | |
# class TreeNode: | |
# def __init__(self, val=0, left=None, right=None): | |
# self.val = val | |
# self.left = left | |
# self.right = right | |
class Solution: | |
def inorderTraversal(self, node: TreeNode) -> List[int]: | |
stack = [] |
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
class Solution: | |
def helper(self, numOpen, numClosed, n, solutionSoFar, result): | |
# Goal | |
if numOpen == n and numClosed == n: | |
result.append(solutionSoFar) | |
return | |
# Choice | |
# Choice 1: Place an open parenthesis |
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
class Solution: | |
# 'i' is the choice for nums[i]. | |
# partialSolution: [] | |
def getSolution(self, partialSolution, nums): | |
res = [] | |
for idx, num in enumerate(nums): | |
if partialSolution[idx] == 1: | |
res.append(num) | |
return res |
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
class Solution: | |
def getHappyString(self, n: int, k: int) -> str: | |
''' | |
Input: | |
n - the length of a happy string | |
k - I want to return the 'k'th item | |
Output: | |
The 'k'th happy string of length 'n' | |
Constraints: | |
Only choose letters from {a,b,c} |
OlderNewer