Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kayden] Week 03 Solutions #393

Merged
merged 7 commits into from
Sep 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions two-sum/kayden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 시간복잡도: O(N)
# 공간복잡도: O(N)
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
check = {}

for idx, num in enumerate(nums):
check[num] = idx

for idx, num in enumerate(nums):
if num * 2 == target:
if check[num] != idx:
return [idx, check[num]]
else:
continue
kjb512 marked this conversation as resolved.
Show resolved Hide resolved

if target - num in check:
return [check[num], check[target - num]]

return []