-
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
[forest000014] Week 2 #719
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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,30 @@ | ||
/* | ||
i번째 칸에 가는 방법은 (1) i-2번째 칸에서 2칸을 점프하거나 (2) i-1번째 칸에서 1칸을 점프하는 2가지 방법 뿐입니다. (MECE함) | ||
따라서, (i번째 칸에 가는 경우의 수) = (i-2번째 칸에 가는 경우의 수) + (i-1번째 칸에 가는 경우의 수) | ||
|
||
Runtime: 0 ms (Beats: 100.00%) | ||
Time Complexity: O(n) | ||
|
||
Memory: 40.47 MB (Beats: 36.79%) | ||
Space Complexity: O(1) | ||
*/ | ||
|
||
class Solution { | ||
public int climbStairs(int n) { | ||
if (n == 1) { | ||
return 1; | ||
} else if (n == 2) { | ||
return 2; | ||
} else { | ||
int prev2 = 1; | ||
int prev1 = 2; | ||
int cur = 0; | ||
for (int i = 3; i <= n; i++) { | ||
cur = prev2 + prev1; | ||
prev2 = prev1; | ||
prev1 = cur; | ||
} | ||
return cur; | ||
} | ||
} | ||
} |
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,32 @@ | ||
/* | ||
s와 t는 알파벳 소문자로만 이루어지므로, 카운팅을 위해 26개의 고정된 key를 사용하면 충분하고, 배열이 가장 간단하고 적합하다고 생각함 | ||
|
||
Runtime: 4 ms (Beats: 76.59%) | ||
Time Complexity: O(n) | ||
|
||
Memory: 43.04 MB (Beats: 78.65%) | ||
Space Complexity: O(1) | ||
*/ | ||
|
||
class Solution { | ||
public boolean isAnagram(String s, String t) { | ||
if (s.length() != t.length()) | ||
return false; | ||
|
||
int[] cnt = new int[26]; | ||
|
||
for (int i = 0; i < s.length(); i++) { | ||
cnt[s.charAt(i) - 'a']++; | ||
} | ||
for (int i = 0; i < t.length(); i++) { | ||
cnt[t.charAt(i) - 'a']--; | ||
} | ||
Comment on lines
+18
to
+23
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. 위에 If문에서 이미 s와 t의 길이를 비교한 이후라면 둘의 길이가 같을테니, 하나의 for문으로 합칠 수 있지 않을까요? :) |
||
|
||
for (int i = 0; i < 26; i++) { | ||
if (cnt[i] != 0) | ||
return false; | ||
} | ||
|
||
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.
로직은 좋다고 생각합니다! 개인적으로는 else if 문을 줄이는 방향으로 하면 가독성 면에서 좀 더 올라가지 않을까 싶어요!