-
-
Notifications
You must be signed in to change notification settings - Fork 361
[jaekwang97] WEEK 02 Solutions #2691
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Solution { | ||
| public int climbStairs(int n) { | ||
| int[] dp = new int[n + 1]; | ||
| if (n <= 3) return n; | ||
| dp[1] = 1; | ||
| dp[2] = 2; | ||
| dp[3] = 3; | ||
|
|
||
| for (int i = 4; i <= n; i++) { | ||
| dp[i] = dp[i - 1] + dp[i - 2]; | ||
| } | ||
|
|
||
| return dp[n]; | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+15
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. DP 정석적인 풀이대로 잘 하신것 같습니다!
|
||
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 왼쪽/오른쪽 누적곱 배열을 만들어 각 위치의 결과를 곱해 구합니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| public int[] productExceptSelf(int[] nums) { | ||
| int n = nums.length; | ||
| int[] right = new int[n + 1]; | ||
| int[] left = new int[n + 1]; | ||
|
|
||
| right[0] = 1; | ||
| for (int i = 1; i <= n; i++) { | ||
| right[i] = right[i - 1] * nums[i - 1]; | ||
| } | ||
|
|
||
| left[n] = 1; | ||
| for (int i = n - 1; i >= 0; i--) { | ||
| left[i] = left[i + 1] * nums[i]; | ||
| } | ||
|
|
||
| int[] answer = new int[n]; | ||
| for (int i = 0; i < n; i++) { | ||
| answer[i] = right[i] * left[i + 1]; | ||
| } | ||
|
|
||
| return answer; | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+26
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. 저는 처음에 잘못된 풀이(나눗셈을 사용한)로 풀었었는데, |
||
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 고정 크기의 카운트 배열로 각 문자의 차이를 반영합니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import java.util.*; | ||
|
|
||
| class Solution { | ||
| public boolean isAnagram(String s, String t) { | ||
| int[] count = new int[26]; | ||
|
|
||
| for (char c : s.toCharArray()) { | ||
| count[c - 'a']++; | ||
| } | ||
|
|
||
| for (char c : t.toCharArray()) { | ||
| count[c - 'a']--; | ||
| } | ||
|
|
||
| for (int n : count) { | ||
| if (n != 0) return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 동적계획법으로 k번째 계단 수를 이전 두 계단의 합으로 계산합니다.
개선 제안: 현재 구현이 적절해 보입니다.