diff --git a/contains-duplicate/jiunshinn.py b/contains-duplicate/jiunshinn.py new file mode 100644 index 000000000..44fab4ad8 --- /dev/null +++ b/contains-duplicate/jiunshinn.py @@ -0,0 +1,30 @@ +# 시간 복잡도 : o(n) +# 공간 복잡도 o(n) + + +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + hashmap = {} + + for i, n in enumerate(nums): + if n in hashmap: + return True + hashmap[n] = i + return False + + +# -------------------------------------------------------------------------------------------------------- # + +# 시간 복잡도 : o(n) +# 공간 복잡도 o(n) + + +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + seen = set() + + for n in nums: + if n in seen: + return True + seen.add(n) + return False diff --git a/two-sum/jiunshinn.py b/two-sum/jiunshinn.py new file mode 100644 index 000000000..73827b846 --- /dev/null +++ b/two-sum/jiunshinn.py @@ -0,0 +1,12 @@ +# time complexity : o(n) +# space complexity : o(n) +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + hashmap = {} + + for i, n in enumerate(nums): + diff = target - n + if diff in hashmap: + return [i, hashmap[diff]] + else: + hashmap[n] = i