Skip to content

Instantly share code, notes, and snippets.

View ksamirdev's full-sized avatar
🥄
I do spoon feeds

Samir ksamirdev

🥄
I do spoon feeds
View GitHub Profile
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
# lets use the bucket sort
# dict
# count: [0, 1, 2, 3]
# freq: [[], [3], [2], [1]]
# basically values how many time have appeared
# (index is count)
n = len(nums)
class Solution:
def longestConsecutive(self, nums: List[int]) -> int:
s = set(nums)
longest = 0
for num in s:
if num - 1 not in s:
next_num = num + 1
length = 1
while next_num in s:
class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
left, right = 0, len(height) - 1
maxArea = 0
while left < right:
class Solution(object):
def threeSum(self, nums):
nums.sort()
res = []
for i in range(len(nums) - 2):
if i > 0 and nums[i] == nums[i-1]: # skip duplicate i
continue
low, high = i + 1, len(nums) - 1
while low < high:
class Solution(object):
def isValid(self, s):
"""
:type s: str
:rtype: bool
"""
stack = []
closeToOpen = {