Skip to content

Commit 81f42e0

Browse files
authored
Merge pull request #1692 from jiunshinn/main
[jiunshinn] WEEK01 solutions
2 parents 6a0a279 + c1c5103 commit 81f42e0

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

contains-duplicate/jiunshinn.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 시간 복잡도 : o(n)
2+
# 공간 복잡도 o(n)
3+
4+
5+
class Solution:
6+
def containsDuplicate(self, nums: List[int]) -> bool:
7+
hashmap = {}
8+
9+
for i, n in enumerate(nums):
10+
if n in hashmap:
11+
return True
12+
hashmap[n] = i
13+
return False
14+
15+
16+
# -------------------------------------------------------------------------------------------------------- #
17+
18+
# 시간 복잡도 : o(n)
19+
# 공간 복잡도 o(n)
20+
21+
22+
class Solution:
23+
def containsDuplicate(self, nums: List[int]) -> bool:
24+
seen = set()
25+
26+
for n in nums:
27+
if n in seen:
28+
return True
29+
seen.add(n)
30+
return False

two-sum/jiunshinn.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# time complexity : o(n)
2+
# space complexity : o(n)
3+
class Solution:
4+
def twoSum(self, nums: List[int], target: int) -> List[int]:
5+
hashmap = {}
6+
7+
for i, n in enumerate(nums):
8+
diff = target - n
9+
if diff in hashmap:
10+
return [i, hashmap[diff]]
11+
else:
12+
hashmap[n] = i

0 commit comments

Comments
 (0)