Skip to content

[HerrineKim] Week 4 #826

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

Merged
merged 8 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions coin-change/HerrineKim.js
Copy link
Contributor

Choose a reason for hiding this comment

The 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,21 @@
// 시간 복잡도: O(n * m)
// 공간 복잡도: O(n)

/**
* @param {number[]} coins
* @param {number} amount
* @return {number}
*/
var coinChange = function(coins, amount) {
const dp = new Array(amount + 1).fill(Infinity);
dp[0] = 0;

for (let coin of coins) {
for (let i = coin; i <= amount; i++) {
dp[i] = Math.min(dp[i], dp[i - coin] + 1);
}
}

return dp[amount] === Infinity ? -1 : dp[amount];
};

17 changes: 17 additions & 0 deletions missing-number/HerrineKim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 시간 복잡도: O(n)
// 공간 복잡도: O(1)

/**
* @param {number[]} nums
* @return {number}
*/
var missingNumber = function(nums) {
const n = nums.length;
// 0부터 n까지의 합 공식: n * (n + 1) / 2
const expectedSum = (n * (n + 1)) / 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 리뷰 의도드린 대로 풀어주셨네요! 👍

// 실제 배열의 합
const actualSum = nums.reduce((sum, num) => sum + num, 0);

return expectedSum - actualSum;
};

25 changes: 25 additions & 0 deletions palindromic-substrings/HerrineKim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 시간 복잡도: O(n^2)
// 공간 복잡도: O(1)

/**
* @param {string} s
* @return {number}
*/
var countSubstrings = function(s) {
let count = 0;

const countPalindrome = (left, right) => {
while (left >= 0 && right < s.length && s[left] === s[right]) {
count++;
left--;
right++;
}
};

for (let i = 0; i < s.length; i++) {
countPalindrome(i, i);
countPalindrome(i, i + 1);
}

return count;
};
Loading