-
-
Notifications
You must be signed in to change notification settings - Fork 362
[jthw1005] WEEK 03 Solutions #2735
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
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,12 @@ | ||
| function combinationSum(candidates, target) { | ||
| const dp = Array.from({ length: target + 1 }, () => []); | ||
| dp[0] = [[]]; | ||
| for (let i = 0; i < candidates.length; i++) { | ||
| for (let j = candidates[i]; j <= target; j++) { | ||
| dp[j].push( | ||
| ...dp[j - candidates[i]].map((item) => [...item, candidates[i]]), | ||
| ); | ||
| } | ||
| } | ||
| return dp[target]; | ||
| } |
|
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 풀이다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| function numDecodings(s) { | ||
| const dp = Array.from({ length: s.length + 1 }, () => 0); | ||
| dp[0] = 1; | ||
| dp[1] = s[0] === '0' ? 0 : 1; | ||
| for (let i = 2; i <= s.length; i++) { | ||
| if (s[i - 1] !== '0') { | ||
| dp[i] += dp[i - 1]; | ||
| } | ||
|
|
||
| const twoDigits = Number(s.slice(i - 2, i)); | ||
| if (twoDigits >= 10 && twoDigits <= 26) { | ||
| dp[i] += dp[i - 2]; | ||
| } | ||
| } | ||
| return dp[s.length]; | ||
| } |
|
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,9 @@ | ||
| function maxSubArray(nums) { | ||
| let max = nums[0]; | ||
| let current = nums[0]; | ||
| for (let i = 1; i < nums.length; i++) { | ||
| current = Math.max(nums[i], current + nums[i]); | ||
| max = Math.max(max, current); | ||
| } | ||
| return max; | ||
| } |
|
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,6 @@ | ||
| function hammingWeight(n) { | ||
| return n | ||
| .toString(2) | ||
| .split('') | ||
| .filter((v) => v === '1').length; | ||
| } |
|
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,4 @@ | ||
| function isPalindrome(s) { | ||
| const letters = s.replace(/[^a-zA-Z0-9]/g, '').toLowerCase(); | ||
|
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. 오 정규식 쓸 생각을 못했었는데 덕분에 깨닫고 갑니다! |
||
| return letters === letters.split('').reverse().join(''); | ||
| } | ||
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 동적 계획법으로 모든 합에 대한 조합을 저장하지만, 각 합에 여러 조합을 저장하므로 공간이 크게 증가할 수 있다.
개선 제안: 현재 구현이 적절해 보입니다.