-
-
Notifications
You must be signed in to change notification settings - Fork 245
[hi-rachel] WEEK 02 solutions #1768
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
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1c489a3
valid-anagram sol (py)
hi-rachel 82cfd90
climbing-stairs sol (py)
hi-rachel ec12b17
product-of-array-except-self sol (py)
hi-rachel dfdc227
3sum sol (py)
hi-rachel cbe8951
validate-binary-search-tree sol (py)
hi-rachel 8e8234a
climbing-stairs 공간 복잡도 최적화 sol (py)
hi-rachel 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,41 @@ | ||
""" | ||
https://leetcode.com/problems/valid-anagram/description/ | ||
두 문자열이 애너그램인지 확인하는 함수를 작성하세요. | ||
애너그램이란 두 문자열이 중복된 알파벳을 같은 개수만큼 포함하고 있는 것을 의미합니다. | ||
TC: O(n) | ||
SC: O(k), k = 알파벳 개수 | ||
""" | ||
|
||
from collections import defaultdict | ||
|
||
class Solution: | ||
def isAnagram(self, s: str, t: str) -> bool: | ||
def makeMap(s: str): | ||
str_map = defaultdict(int) | ||
for char in s: | ||
str_map[char] += 1 | ||
return str_map | ||
|
||
return makeMap(s) == makeMap(t) | ||
|
||
|
||
""" | ||
정렬 풀이 | ||
TC: O(nlogn) | ||
SC: O(1) | ||
""" | ||
def isAnagram(s: str, t: str) -> bool: | ||
return sorted(s) == sorted(t) | ||
|
||
""" | ||
Counter 사용 풀이 | ||
TC: O(n) | ||
SC: O(k) | ||
""" | ||
from collections import Counter | ||
|
||
def isAnagram(s: str, t: str) -> bool: | ||
return Counter(s) == Counter(t) |
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.
코드를 구조화하여 세가지 방법을 모두 제공한 것이 매우 좋습니다 :)
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.
@printjin-gmailcom 이번에 재수 2번째 도전이라 여러 풀이로 도전했습니다.
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.
안그래도 꽤나 익숙한 아이디이긴했어요 ㅎㅎ 코드가 다 깔끔하고 좋아서 많이 배워갑니다다. 5기 화이팅 :)