diff --git a/contains-duplicate/JiHyeonSu.py b/contains-duplicate/JiHyeonSu.py new file mode 100644 index 000000000..707ba5593 --- /dev/null +++ b/contains-duplicate/JiHyeonSu.py @@ -0,0 +1,5 @@ +# 중복제거 후 길이 확인 문제 +# 시간복잡도 및 공간복잡도 O(n) +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + return len(nums) != len(set(nums)) diff --git a/two-sum/JiHyeonSu.py b/two-sum/JiHyeonSu.py new file mode 100644 index 000000000..a136ade82 --- /dev/null +++ b/two-sum/JiHyeonSu.py @@ -0,0 +1,11 @@ +# 해시맵을 활용한 두 수의 합 구현 +# 시간복잡도 및 공간복잡도 O(n) +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + n_map = {} + + for i, num in enumerate(nums): + diff = target - num + if diff in n_map: + return [n_map[diff], i] + n_map[num] = i