-
-
Notifications
You must be signed in to change notification settings - Fork 362
[Hoonjichoi] WEEK 02 solutions #2696
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
+57
−0
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c88a82
valid-anagram
Hoonjichoi1 814c06b
climbing-stairs
Hoonjichoi1 cc3e002
climbing-stairs
Hoonjichoi1 34ec223
climbing-stairs
Hoonjichoi1 1cfbf82
climbing-stairs
Hoonjichoi1 6386bf3
remove old filename
Hoonjichoi1 daee88b
Feedback updated valid-anagram/hoonjichoi1.java
Hoonjichoi1 dd0e8ec
Feedback updated climbing-stairs/hoonjichoi1.java
Hoonjichoi1 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,24 @@ | ||
|
|
||
| /* | ||
| f(45) = f(44) + f(43) | ||
| f(44) = f(43) + f(42) | ||
| . | ||
| . | ||
| . | ||
| f(3) = f(2) + f(1) | ||
| f(2) = 2 | ||
| f(1) = 1 | ||
| */ | ||
| class Solution { | ||
| public int climbStairs(int n) { | ||
| if (n <= 2) return n; | ||
|
|
||
| int prev = 1, cur = 2; | ||
| for (int i = 2; i < n ; i++) { | ||
| int temp = cur; | ||
| cur += prev; | ||
| prev = temp; | ||
| } | ||
| return cur; | ||
| } | ||
| } |
|
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,33 @@ | ||
| import java.util.HashMap; | ||
|
|
||
| public class hoonjichoi1 { | ||
| public boolean isAnagram(String s, String t) { | ||
| if (s.equals(t)) | ||
| return true; | ||
| if (s.length() != t.length()) | ||
| return false; | ||
|
|
||
| HashMap<Character, Integer> map = new HashMap<>(); | ||
|
|
||
| for (int i = 0; i < s.length(); i++) { | ||
| Character c = s.charAt(i); | ||
| map.put(c, map.getOrDefault(c, 0) + 1); | ||
| } | ||
|
|
||
| for (int j = 0; j < t.length(); j++) { | ||
| Character c = t.charAt(j); | ||
| if (!map.containsKey(c) || map.get(c) <= 0) { | ||
| return false; | ||
| } | ||
|
|
||
| map.put(c, map.get(c) - 1); | ||
| } | ||
|
Hoonjichoi1 marked this conversation as resolved.
|
||
|
|
||
| for (Integer i : map.values()) { | ||
| if (i < 0) { | ||
| return false; | ||
| } | ||
| } | ||
|
Comment on lines
+26
to
+30
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. 이 반복문은 2번째 반복문에서 처리해줘도 좋을 듯 싶습니다..! |
||
| return true; | ||
| } | ||
| } | ||
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
풀이 1:
Solution.climbStairs— Time: O(n) / Space: O(1)피드백: 상수 공간으로 이전 두 항만 저장하고 순차적으로 업데이트하여 시간 복잡도는 선형으로 구해진다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2:
hoonjichoi1.isAnagram— Time: O(n + m) / Space: O(k)피드백: 두 문자열의 길이가 n, m일 때 해시맵에 최대 서로 다른 문자 수만큼 공간이 필요하고, 모든 문자의 빈도 차이를 확인한다.
개선 제안: 현재 구현이 적절해 보입니다.