-
-
Notifications
You must be signed in to change notification settings - Fork 361
[sonshn] WEEK 02 Solutions #2702
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
Open
sonshn
wants to merge
10
commits into
DaleStudy:main
Choose a base branch
from
sonshn:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+39
−0
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fcb31f4
contains-duplicate solution
sonshn 6c69e25
two-sum solution
sonshn 9d7e093
top-k-frequent-elements solution
sonshn 7766ac3
top-k-frequent-elements 풀이 추가
sonshn 32eb8b6
longest-consecutive-sequence solution
sonshn a1e4dde
house-robber solution
sonshn d460b73
valid-anagram solution
sonshn f3c4ef9
Merge branch 'DaleStudy:main' into main
sonshn 8d1ab21
climbing-stairs solution
sonshn 63da3f1
Merge branch 'main' of https://github.com/sonshn/leetcode-study
sonshn 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,20 @@ | ||
| /** | ||
| * dp[i] = dp[i - 1] + dp[i - 2] | ||
| */ | ||
| class Solution { | ||
| public int climbStairs(int n) { | ||
| if (n <= 2) { | ||
| return n; | ||
| } | ||
|
|
||
| int[] dp = new int[n + 1]; | ||
| dp[1] = 1; | ||
| dp[2] = 2; | ||
|
|
||
| for (int i = 3; i <= n; i++) { | ||
| dp[i] = dp[i - 1] + dp[i - 2]; | ||
| } | ||
|
|
||
| return dp[n]; | ||
| } | ||
| } |
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 두 문자열의 문자 배열을 정렬 후 비교하는 간단한 구현입니다. 개선 제안: ASCII 범위가 한정된 경우 카운팅 정렬처럼 선형 시간으로 개선 가능하고, 불필요한 정렬을 피하려면 문자 빈도수 비교로 구현해도 같습니다. |
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,19 @@ | ||
| import java.util.*; | ||
|
|
||
| /** | ||
| * String to char array, sort, and compare | ||
| * | ||
| * 시간 복잡도: O(nlogn) | ||
| * 공간 복잡도: O(n) | ||
| */ | ||
| class Solution { | ||
| public boolean isAnagram(String s, String t) { | ||
| char[] sArray = s.toCharArray(); | ||
| char[] tArray = t.toCharArray(); | ||
|
|
||
| Arrays.sort(sArray); | ||
| Arrays.sort(tArray); | ||
|
|
||
| return Arrays.equals(sArray, tArray); | ||
| } | ||
| } |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: dp 배열을 사용해 각 단계의 경우의 수를 저장하며 i번째 값은 직전 값과 그 전 값을 더해 구합니다.
개선 제안: 메모리 사용을 줄이고 O(1) 공간으로 개선 가능(두 변수로만 상태를 유지하는 방법)