Skip to content

Commit c35ade2

Browse files
authored
Merge pull request #1704 from Do-heewan/main
[do-heewan] WEEK 01 Solutions
2 parents 34826b1 + 596cce5 commit c35ade2

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

contains-duplicate/do-heewan.py

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+
sets = set(nums)
4+
5+
if len(nums) != len(sets):
6+
return True
7+
return False
8+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
def topKFrequent(self, nums, k):
3+
count = {}
4+
result = []
5+
6+
for i in nums:
7+
if i not in count:
8+
count[i] = 1
9+
else:
10+
count[i] += 1
11+
12+
count = sorted(count.items(), key=lambda x : x[1], reverse=True)
13+
14+
return [item[0] for item in count[:k]]
15+

two-sum/do-heewan.py

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

0 commit comments

Comments
 (0)