Skip to content

Instantly share code, notes, and snippets.

@ericness
ericness / 200_number_of_islands.py
Last active March 19, 2022 18:47
LeetCode 200 Homegrown solution
from typing import List
class Solution:
def numIslands(self, grid: List[List[str]]) -> int:
"""Find number of islands in grid.
Args:
grid (List[List[str]]): Grid with 0s and 1s
from collections import defaultdict
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
"""Count longest sequence with no repeating characters
Args:
s (str): String to analyze
@ericness
ericness / 1_two_sum.py
Created March 8, 2022 02:22
LeetCode 1 solution
from typing import List
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
"""Find indexes of numbers that sum to target number.
Args:
nums (List[int]): List of numbers to consider.
target (int): Number to sum to.
from collections import defaultdict
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
"""Calculate the longer repeating character
string when replacing with one letter
Args:
s (str): String to evaluate
from collections import defaultdict
from typing import List
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
"""Calculate the longer repeating character
string when replacing with one letter
Args:
def calculate_length(self, diffs: List[int], k: int) -> int:
"""Calculate maximum sequence length based
on the differences between character positions
Args:
diffs (List[int]): List of position differences
k (int): Number of characters to replace
Returns:
int: Maximum length of replacement
def calculate_length(self, diffs: List[int], k: int) -> int:
"""Calculate maximum sequence length based
on the differences between character positions
Args:
diffs (List[int]): List of position differences
k (int): Number of characters to replace
Returns:
int: Maximum length of replacement
from collections import defaultdict
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
"""Calculate the longer repeating character
string when replacing with one letter
Args:
s (str): String to evaluate
from typing import List
class Solution:
def findMin(self, nums: List[int]) -> int:
"""Find minimum element in rotated sorted array.
Args:
nums (List[int]): Rotated sorted array
@ericness
ericness / 11_container_with_most_water.py
Created February 21, 2022 02:02
LeetCode 11 solution
from typing import List
class Solution:
def maxArea(self, height: List[int]) -> int:
"""Calculate max area between array elements.
Args:
height (List[int]): List of heights