-
-
Notifications
You must be signed in to change notification settings - Fork 338
[ppxyn1] WEEK 02 solutions #2399
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 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
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 |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| #idea: dictionary | ||
| from collections import Counter | ||
| # class Solution: | ||
| # def isAnagram(self, s: str, t: str) -> bool: | ||
| # s_dic = Counter(sorted(s)) | ||
| # t_dic = Counter(sorted(t)) | ||
| # return s_dic==t_dic | ||
|
|
||
| class Solution: | ||
| def isAnagram(self, s: str, t: str) -> bool: | ||
| s_dic = Counter(sorted(s)) | ||
| t_dic = Counter(sorted(t)) | ||
| print(s_dic, t_dic) | ||
| return s_dic==t_dic | ||
| # fixed | ||
| # do not need to both Counter and sorting | ||
|
|
||
|
|
||
|
|
||
| # Trial and Error | ||
| ''' | ||
| When you call sorted() on a dictionary, it only extracts and sorts the keys,and the values are completely ignored. | ||
| # Ans 1 (Only Counter) | ||
| # Time Complexity: O(N) | ||
| class Solution: | ||
| def isAnagram(self, s: str, t: str) -> bool: | ||
| s_dic = Counter(s) | ||
| t_dic = Counter(t) | ||
| print(s_dic, t_dic) | ||
| return sorted(s_dic)==sorted(t_dic) | ||
| ''' | ||
|
|
||
|
|
||
|
|
||
| return s_dic==t_dic | ||
|
|
||
| # Ans 2 (Only Sorting) | ||
| # Time Complexity: O(Nlog(N)) | ||
| class Solution: | ||
| def isAnagram(self, s: str, t: str) -> bool: | ||
| s_arr = sorted(s) | ||
| t_arr = sorted(t) | ||
| return s_arr==t_arr | ||
|
|
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.
DP 배열을 이용해서 dp[i] = dp[i-1] + dp[i-2]를 적용한 정석 풀이인 것 같습니다.
해당 문제는 이전 두 값만 사용하기 때문에 배열을 사용하지 않고 두 변수만 유지하면 공간 복잡도를 O(1)로 줄일 수도 있을 것 같다고 생각합니다.