-
Notifications
You must be signed in to change notification settings - Fork 126
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
[jinah92] Week 2 #752
Merged
Merged
[jinah92] Week 2 #752
Changes from all commits
Commits
Show all changes
5 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 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 @@ | ||
# 공간복잡도 : O(1), 시간복잡도 : O(N^2) | ||
class Solution: | ||
def threeSum(self, nums: List[int]) -> List[List[int]]: | ||
three_sums = set() | ||
nums.sort() | ||
|
||
for i in range(len(nums)-2): | ||
low, high = i + 1, len(nums)-1 | ||
while low < high: | ||
three_sum = nums[i] + nums[high] + nums[low] | ||
if three_sum < 0: | ||
low += 1 | ||
elif three_sum > 0: | ||
high -= 1 | ||
else: | ||
three_sums.add((nums[i], nums[high], nums[low])) | ||
low, high = low+1, high-1 | ||
|
||
return list(three_sums) | ||
|
This file contains 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,11 @@ | ||
# 공간복잡도: O(1), 시간복잡도: O(n) | ||
class Solution: | ||
def climbStairs(self, n: int) -> int: | ||
if n < 3: | ||
return n | ||
|
||
prev, curr = 1, 2 | ||
for num in range(3, n+1): | ||
prev, curr = curr, prev + curr | ||
|
||
return curr |
This file contains 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,14 @@ | ||
# 공간복잡도: O(n), 시간복잡도: O(n) | ||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
char_set_1, char_set_2 = {}, {} | ||
|
||
for ch in s: | ||
char_set_1[ch] = 0 if ch not in char_set_1 else char_set_1[ch] + 1 | ||
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. 조건 표현식도 좋지만, 이렇게 긴 경우에는 .get 메서드의 기본값을 사용해보시면 가독성에 도움이 되실 것 같습니다. |
||
|
||
for ch in t: | ||
char_set_2[ch] = 0 if ch not in char_set_2 else char_set_2[ch] + 1 | ||
|
||
# dictionary의 모든 요소 종류와 개수가 일치해야 함 | ||
return char_set_1 == char_set_2 | ||
|
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.
three_sums의 크기 때문에 공간복잡도가 O(1) 보다 클 것 같습니다.