Skip to content

Instantly share code, notes, and snippets.

@ericness
ericness / pyinstrument.txt
Created March 21, 2022 23:11
LeetCode 200 pyinstrument output
_ ._ __/__ _ _ _ _ _/_ Recorded: 18:04:16 Samples: 277
/_//_/// /_\ / //_// / //_'/ // Duration: 0.277 CPU time: 0.277
/ _/ v4.1.1
Program: 200_number_of_islands.py
0.277 <module> <string>:1
[4 frames hidden] <string>, runpy
0.277 _run_code runpy.py:64
└─ 0.277 <module> 200_number_of_islands.py:8
@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