Skip to content

Commit fce3f30

Browse files
authored
Merge pull request #2011 from deepInTheWoodz/main
[deepInTheWoodz] WEEK 01 solutions
2 parents 35b6f16 + a95f534 commit fce3f30

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def containsDuplicate(self, nums: List[int]) -> bool:
3+
s = set()
4+
for num in nums:
5+
if num in s:
6+
return True
7+
s.add(num)
8+
return False
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3+
counter = dict()
4+
5+
for num in nums:
6+
if num in counter:
7+
counter[num] += 1
8+
else:
9+
counter[num] = 1
10+
11+
return [num[0] for num in sorted(counter.items(), key=lambda x: x[1])[-k:]]

two-sum/deepInTheWoodz.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def twoSum(self, nums: List[int], target: int) -> List[int]:
3+
passed = dict()
4+
5+
for i, num in enumerate(nums):
6+
other = target - num
7+
if other in passed:
8+
return [passed[other], i]
9+
passed[num] = i

0 commit comments

Comments
 (0)