Skip to content

Commit 10e5a5b

Browse files
Merge pull request #2024 from mandel-17/main
[mandel-17] WEEK 01 solutions
2 parents 70dd17b + 8d3ed21 commit 10e5a5b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

contains-duplicate/mandel-17.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
class Solution:
4+
def containsDuplicate(self, nums: List[int]) -> bool:
5+
stack_list = []
6+
for i, n in enumerate(nums[:-1]):
7+
stack_list.append(n)
8+
if nums[i+1] in stack_list:
9+
return True
10+
else:
11+
if i == len(nums[:-2]):
12+
return False
13+
continue
14+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List
2+
3+
class Solution:
4+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
5+
nums_dict = {}
6+
for n in nums:
7+
if n not in nums_dict.keys():
8+
nums_dict[n] = 1
9+
else:
10+
nums_dict[n] += 1
11+
12+
frequent_rank = sorted(nums_dict.items(), key=lambda item:item[1], reverse=True)
13+
return [frequent_rank[j][0] for j in range(k)]
14+

two-sum/mandel-17.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
class Solution:
4+
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
for i, v in enumerate(nums):
6+
second_value = target - v
7+
8+
if second_value in nums[i+1:]:
9+
return [i, nums[i+1:].index(second_value) + i+1]
10+

0 commit comments

Comments
 (0)