Skip to content

Instantly share code, notes, and snippets.

@ericness
ericness / 53_maximum_subarray.py
Created February 1, 2022 00:37
LeetCode 53 final answer
from typing import List
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
"""Find subarray with largest sum
Args:
nums (List[int]): Array of numbers
@ericness
ericness / 53_maximum_subarray.py
Created January 28, 2022 00:34
LeetCode 53 Attempt 4
from typing import List
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
"""Find subarray with largest sum
Args:
nums (List[int]): Array of numbers
@ericness
ericness / 53_maximum_subarray.py
Created January 22, 2022 19:18
LeetCode 53 O(N) attempt 1
from typing import List
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
"""Find subarray with largest sum
Args:
nums (List[int]): Array of numbers
@ericness
ericness / 53_maximum_subarray.py
Last active January 21, 2022 14:28
LeetCode 53 Brute Force
from typing import List
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
"""Find subarray with largest sum
Args:
nums (List[int]): Array of numbers
@ericness
ericness / 238_product_of_array_except_self.py
Created January 20, 2022 02:15
LeetCode 238 O(1) memory
from typing import List
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
"""Calculate an array of the products for every element
in the array except the one at the same index.
Args:
nums (List[int]): Array of ints
@ericness
ericness / 238_product_of_array_except_self.py
Created January 17, 2022 00:00
LeetCode 238 O(N) solution 2
suffix_i = array_length - i - 1
suffix_products[suffix_i] = (
nums[suffix_i + 1] * suffix_products[suffix_i + 1]
)
@ericness
ericness / 238_product_of_array_except_self.py
Last active January 16, 2022 23:51
LeetCode 238 O(N) solution
from typing import List
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
"""Calculate an array of the products for every element
in the array except the one at the same index.
Args:
nums (List[int]): Array of ints
@ericness
ericness / 238_product_of_array_except_self.py
Created January 15, 2022 22:08
LeetCode 238 Brute Force Attempt 2
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
"""Calculate an array of the products for every element
in the array except the one at the same index.
Args:
nums (List[int]): Array of ints
Returns:
List[int]: Array of products
import math
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
"""Calculate an array of the products for every element
in the array except the one at the same index.
Args:
nums (List[int]): Array of ints
@ericness
ericness / 20_valid_parentheses.py
Created January 13, 2022 00:19
LeetCode 20 fix
return len(paren_order) == 0