-
-
Notifications
You must be signed in to change notification settings - Fork 361
[j2h30728] WEEK 04 Solutions #2760
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
5eddbc3
b5a3e02
2d35b91
d0b93d3
8bcd582
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,14 @@ | ||
| function coinChange(coins: number[], amount: number): number { | ||
| const dp = new Array(amount + 1).fill(amount + 1); | ||
| dp[0] = 0; | ||
|
|
||
| for (let i = 1; i <= amount; i++) { | ||
| for (const coin of coins) { | ||
| if (i - coin >= 0) { | ||
| dp[i] = Math.min(dp[i], 1 + dp[i - coin]); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return dp[amount] > amount ? -1 : dp[amount]; | ||
|
Comment on lines
+2
to
+13
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,12 @@ | ||
| function findMin(nums: number[]): number { | ||
| const n = nums.length - 1; | ||
|
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. 변수 명으로 n을 사용하신 이유가 있을까요? |
||
| let last = nums[n]; | ||
| let left = 0, right = n; | ||
|
|
||
| while(left < right){ | ||
| const mid = (left + right) >> 1; | ||
| if(nums[mid] > last) left = mid + 1; | ||
| else right = mid; | ||
|
Comment on lines
+3
to
+9
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. 이진탐색인데 last가 고정되어 있네요. 잘 이해가 안되서 그런데 이 부분 설명해주실 수 있을까요? |
||
| } | ||
| return nums[left]; | ||
| }; | ||
|
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,20 @@ | ||
| /** | ||
| * Definition for a binary tree node. | ||
| * class TreeNode { | ||
| * val: number | ||
| * left: TreeNode | null | ||
| * right: TreeNode | null | ||
| * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { | ||
| * this.val = (val===undefined ? 0 : val) | ||
| * this.left = (left===undefined ? null : left) | ||
| * this.right = (right===undefined ? null : right) | ||
| * } | ||
| * } | ||
| */ | ||
|
|
||
| function maxDepth(root: TreeNode | null): number { | ||
| if(!root) return 0; | ||
| const maxLeft = maxDepth(root.left); | ||
| const maxRight = maxDepth(root.right); | ||
| return Math.max(maxLeft, maxRight) + 1; | ||
| }; |
|
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,29 @@ | ||
| /** | ||
| * Definition for singly-linked list. | ||
| * class ListNode { | ||
| * val: number | ||
| * next: ListNode | null | ||
| * constructor(val?: number, next?: ListNode | null) { | ||
| * this.val = (val===undefined ? 0 : val) | ||
| * this.next = (next===undefined ? null : next) | ||
| * } | ||
| * } | ||
| */ | ||
|
|
||
| function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode | null { | ||
| const root = new ListNode(); | ||
| let tail = root; | ||
|
|
||
| while(list1 !== null && list2 !== null){ | ||
| if(list1.val <= list2.val){ | ||
| tail.next = list1; | ||
| list1 = list1.next; | ||
| }else{ | ||
| tail.next = list2; | ||
| list2 = list2.next; | ||
| } | ||
| tail = tail.next; | ||
| } | ||
| tail.next = list1 !== null ? list1 : list2; | ||
| return root.next; | ||
| }; |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 외부 반복으로 모든 금액에 대해 각 동전을 활용한 최소 개수를 갱신하는 표를 사용한다.
개선 제안: 현재 구현이 적절해 보입니다.