-
-
Notifications
You must be signed in to change notification settings - Fork 360
[Chanz] WEEK 01 Solutions #2658
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
Merged
+30
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class Solution: | ||
| def containsDuplicate(self, nums: List[int]) -> bool: | ||
| hashmap = dict() | ||
| sorted(nums) | ||
| for num in nums: | ||
| if hashmap.get(num, False) == True: | ||
| return True | ||
| else : | ||
| hashmap[num] = True | ||
| return False | ||
|
Chanz82 marked this conversation as resolved.
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bot님. 질문에 자동응답 하나요?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 해시맵에 이전에 본 값의 인덱스를 저장하고, 현재 값과 목표 차이가 존재하는지 확인합니다. 개선 제안: 현재 구현이 올바르게 작동하는 한, 더 간단한 주석만 남겨도 충분합니다.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| class Solution: | ||
| def twoSum(self, nums: List[int], target: int) -> List[int]: | ||
|
|
||
| ## 공간 복잡도 : O(n) | ||
| ## - n 개수 만큼의 hashmap 공간만을 사용하므로 공간복잡도가 O(n)이라고 생각합니다. | ||
|
|
||
| ## 시간 복잡도 : O(n) | ||
| ## - hashmap에 값과 idx를 매칭하는 작업을 n번 수행합니다. | ||
| ## - 이후 다시 nums를 순회하면서 target이 되는 짝을 찾습니다. | ||
| ## - 따라서 Worst N번 이므로, 2n = O(n)이라고 생각합니다. | ||
|
|
||
| hashmap = dict() | ||
|
|
||
| for idx, num in enumerate(nums): | ||
| possible_match = target - num | ||
| if possible_match in hashmap: | ||
| return [idx, hashmap[possible_match]] | ||
| else: | ||
| hashmap[num] = idx | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 해시맵에 방문 여부를 저장해 중복 여부를 인식합니다. 반복마다 상수시간 조회/삽입이 가능하므로 전체 시간은 선형이고 추가 공간도 선형입니다.
개선 제안: 현재 구현은 전통적인 해시맵 기반 풀이로 적절합니다.