diff --git a/contains-duplicate/mandel-17.py b/contains-duplicate/mandel-17.py new file mode 100644 index 0000000000..4aa2f4a003 --- /dev/null +++ b/contains-duplicate/mandel-17.py @@ -0,0 +1,14 @@ +from typing import List + +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + stack_list = [] + for i, n in enumerate(nums[:-1]): + stack_list.append(n) + if nums[i+1] in stack_list: + return True + else: + if i == len(nums[:-2]): + return False + continue + diff --git a/top-k-frequent-elements/mandel-17.py b/top-k-frequent-elements/mandel-17.py new file mode 100644 index 0000000000..775721df2f --- /dev/null +++ b/top-k-frequent-elements/mandel-17.py @@ -0,0 +1,14 @@ +from typing import List + +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + nums_dict = {} + for n in nums: + if n not in nums_dict.keys(): + nums_dict[n] = 1 + else: + nums_dict[n] += 1 + + frequent_rank = sorted(nums_dict.items(), key=lambda item:item[1], reverse=True) + return [frequent_rank[j][0] for j in range(k)] + diff --git a/two-sum/mandel-17.py b/two-sum/mandel-17.py new file mode 100644 index 0000000000..029fde1a89 --- /dev/null +++ b/two-sum/mandel-17.py @@ -0,0 +1,10 @@ +from typing import List + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + for i, v in enumerate(nums): + second_value = target - v + + if second_value in nums[i+1:]: + return [i, nums[i+1:].index(second_value) + i+1] +