Skip to content

Instantly share code, notes, and snippets.

@ericness
ericness / 141_linked_list_cycle.py
Created February 19, 2022 23:24
LeetCode 141 solution
from collections import defaultdict
from typing import Optional
# Definition for singly-linked list.
class ListNode:
"""Node in a linked list"""
def __init__(self, x):
self.val = x
@ericness
ericness / 15_3_sum.py
Created February 18, 2022 02:20
LeetCode 15 sorted solution
from typing import List
class Solution:
"""Solution class for three sum"""
def threeSum( # pylint: disable=invalid-name
self, nums: List[int]
) -> List[List[int]]:
"""Find unique triplets that sum to zero.
@ericness
ericness / 167_two_sum_ii_input_array_is_sorted.py
Created February 15, 2022 00:12
LeetCode 167 two pointer
from typing import List
class Solution:
"""Solution class for Two Sum"""
def twoSum( # pylint: disable=invalid-name
self, numbers: List[int], target: int
) -> List[int]:
"""Find the indices of the two numbers that add to target.
@ericness
ericness / 167_two_sum_ii_input_array_is_sorted.py
Created February 12, 2022 22:15
LeetCode 167 binary search attempt 2
from typing import List
class Solution:
"""Solution class for Two Sum"""
def twoSum( # pylint: disable=invalid-name
self, numbers: List[int], target: int
) -> List[int]:
"""Find the indices of the two numbers that add to target.
from typing import List
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
"""Find the indices of the two numbers that add to target.
Args:
numbers (List[int]): Sorted list of ints
target (int): Target to sum to
@ericness
ericness / 167_two_sum_ii_input_array_is_sorted.py
Created February 11, 2022 00:10
LeetCode 167 - brute force
from typing import List
class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:
"""Find the indices of the two numbers that add to target.
Args:
numbers (List[int]): Sorted list of ints
target (int): Target to sum to
@ericness
ericness / 15_3_sum.py
Last active February 5, 2022 23:40
LeetCode 15 passing solution
import copy
from collections import defaultdict
from typing import List
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
"""Find unique triplets that sum to zero.
Args:
@ericness
ericness / 15_3_sum.py
Created February 5, 2022 16:37
LeetCode 15 space hog
import copy
from collections import defaultdict
from typing import List
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
"""Find unique triplets that sum to zero.
Args:
@ericness
ericness / 15_3_sum.py
Created February 3, 2022 23:26
LeetCode 15 O(N2) solution
from typing import List
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
"""Find unique triplets that sum to zero.
Args:
nums (List[int]): List of numbers
@ericness
ericness / 15_3_sum.py
Created February 3, 2022 23:09
LeetCode 15 brute force
from typing import List
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
"""Find unique triplets that sum to zero.
Args:
nums (List[int]): List of numbers