Skip to content

Commit 76ff87f

Browse files
authored
Merge pull request #2022 from jun-brro/main
[jun-brro] WEEK 01 solutions
2 parents 5c5d69f + eef2a8a commit 76ff87f

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

contains-duplicate/jun-brro.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution(object):
2+
def containsDuplicate(self, nums):
3+
return len(set(nums))!=len(nums)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def topKFrequent(self, nums, k):
3+
"""
4+
:type nums: List[int]
5+
:type k: int
6+
:rtype: List[int]
7+
"""
8+
freq = {}
9+
for n in nums:
10+
freq[n] = freq.get(n, 0) + 1
11+
12+
buckets = [[] for _ in range(len(nums) + 1)]
13+
for num, count in freq.items():
14+
buckets[count].append(num)
15+
16+
result = []
17+
for count in range(len(nums), 0, -1):
18+
for num in buckets[count]:
19+
result.append(num)
20+
if len(result) == k:
21+
return result

two-sum/jun-brro.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution(object):
2+
def twoSum(self, nums, target):
3+
for i in range(len(nums)):
4+
for j in range(i + 1, len(nums)):
5+
if nums[i] + nums[j] == target:
6+
return [i, j]

0 commit comments

Comments
 (0)