diff --git a/contains-duplicate/deepInTheWoodz.py b/contains-duplicate/deepInTheWoodz.py new file mode 100644 index 000000000..18a40f5f8 --- /dev/null +++ b/contains-duplicate/deepInTheWoodz.py @@ -0,0 +1,8 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + s = set() + for num in nums: + if num in s: + return True + s.add(num) + return False diff --git a/top-k-frequent-elements/deepInTheWoodz.py b/top-k-frequent-elements/deepInTheWoodz.py new file mode 100644 index 000000000..b1ffe48ca --- /dev/null +++ b/top-k-frequent-elements/deepInTheWoodz.py @@ -0,0 +1,11 @@ +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + counter = dict() + + for num in nums: + if num in counter: + counter[num] += 1 + else: + counter[num] = 1 + + return [num[0] for num in sorted(counter.items(), key=lambda x: x[1])[-k:]] diff --git a/two-sum/deepInTheWoodz.py b/two-sum/deepInTheWoodz.py new file mode 100644 index 000000000..b93869aa9 --- /dev/null +++ b/two-sum/deepInTheWoodz.py @@ -0,0 +1,9 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + passed = dict() + + for i, num in enumerate(nums): + other = target - num + if other in passed: + return [passed[other], i] + passed[num] = i