-
-
Notifications
You must be signed in to change notification settings - Fork 244
[wozlsla] WEEK 11 solutions #1934
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
+52
−0
Merged
Changes from all commits
Commits
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,52 @@ | ||
from typing import List | ||
|
||
|
||
""" | ||
distinct | ||
두 배열의 차이 -> 순회를 어떻게? -> 리스트 > 해시테이블 (t) | ||
|
||
# Sol 1 | ||
|
||
시간 복잡도: O(n) | ||
- 1. Set 생성: O(n) | ||
- 2. 반복문 + 해시셋 검사: O(n) + O(1) | ||
|
||
공간 복잡도: O(n) | ||
|
||
# Sol 2 | ||
|
||
시간 복잡도: O(n) | ||
- 1. 0부터 n까지의 전체 합 계산: O(1) | ||
- 2. nums 배열 요소들의 합 계산: O(n) | ||
- 3. 차이가 사라진 숫자: O(1) | ||
|
||
공간 복잡도: O(1) | ||
|
||
""" | ||
|
||
|
||
# Sol 1) | ||
class Solution: | ||
def missingNumber(self, nums: List[int]) -> int: | ||
|
||
table = set(nums) | ||
|
||
for i in range(0, len(nums) + 1): | ||
if i not in table: | ||
return i | ||
else: | ||
continue | ||
|
||
|
||
# Sol 2) | ||
class Solution: | ||
def missingNumber(self, nums: List[int]) -> int: | ||
n = len(nums) | ||
|
||
# 0부터 n까지의 전체 합 (가우스 공식) | ||
sum_total = n * (n + 1) // 2 | ||
|
||
# nums 배열 요소들의 합 | ||
sum_nums = sum(nums) | ||
|
||
return sum_total - sum_nums |
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.
Uh oh!
There was an error while loading. Please reload this page.