Skip to content
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
32 changes: 32 additions & 0 deletions combination-sum/yuhyeon99.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 각각 다른 정수 배열 candidates와, 목표 정수 target이 주어진다.
* 반환하라, 타겟과 값이 같은 합을 보유한 고유한 조합을.
* 조합은 어떤 순서(any order)로든 반환할 수 있습니다.
* 같은 숫자를 여러 조합에 무제한(unlimited number of times) 쓸 수 있습니다.
* 선택한 숫자 중 적어도 하나의 빈도가 다르다면 두 조합은 고유합니다.
* target은 150보다 낮은 숫자입니다.
*
* @param {number[]} candidates
* @param {number} target
* @return {number[][]}
*/
var combinationSum = function(candidates, target) {
var result = [];
var nums = [];
function dfs(start, total) {
if (total > target) return;
if (total === target) result.push(nums.slice());
Copy link
Contributor

Choose a reason for hiding this comment

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

깔끔하게 잘 써주셔서 잘 읽혔습니다. 사소한 부분이긴 하지만 해당 부분에서 바로 return해도 되지 않을까 싶네요!



for (let i = start; i < candidates.length; i ++) {
let num = candidates[i];
nums.push(num);
dfs(i, total + num);
nums.pop();
}

}
dfs(0, 0);

return result;
};
36 changes: 36 additions & 0 deletions decode-ways/yuhyeon99.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 인코드 된 메세지를 디코드(decode)하려면, 맵핑의 규칙을 반대로 적용하여 숫자를 다시 알파벳 대문자로 돌려놔야 한다.
* 예를 들어, 숫자 11106은 1 1 10 6으로 분할하면 AAJF로 디코드할 수도 있고, 11 10 6으로 분할하면 KJF로도 디코드할
수 있다.
* 문자열 타입의 숫자가 주어졌을 때 알파벳 문자열로 디코드할 수 있는 방법의 개수를 구하라.
* @param {string} s
* @return {number}
*/
var numDecodings = function(s) {
const memo = new Map();
memo.set(s.length, 1);

function dfs(start) {
if (memo.has(start)) {
return memo.get(start);
}

// 0으로 시작하면 해석 불가
if (s[start] === "0") {
memo.set(start, 0);
return 0;
}

let count = dfs(start + 1); // 한 글자 해석

// 두 글자 해석 가능한 경우
if (start + 1 < s.length && parseInt(s.substring(start, start + 2)) <= 26) {
count += dfs(start + 2);
}

memo.set(start, count);
return count;
}

return dfs(0);
};
13 changes: 13 additions & 0 deletions maximum-subarray/yuhyeon99.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @param {number[]} nums
* @return {number}
*/
var maxSubArray = function(nums) {
let maxSum = nums[0];
let sum = 0;
nums.forEach((num) => {
sum = Math.max(sum + num, num);
maxSum = Math.max(sum, maxSum);
});
return maxSum;
};
12 changes: 12 additions & 0 deletions number-of-1-bits/yuhyeon99.js
Copy link
Contributor

Choose a reason for hiding this comment

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

잘 풀어주셨습니다! 저도 좀 찾아보다가 이렇게도 풀기도 하는구나 싶은 좋은 참고자료 하나 발견하여 공유드립니다!

https://blog.naver.com/jinhan814/222540111549

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 @@
/**
* @param {number} n
* @return {number}
*/
var hammingWeight = function(n) {
var answer = 0;
while(n >= 1) {
if (n % 2 === 1) answer ++;
n = Math.floor(n/2);
}
return answer;
};
11 changes: 11 additions & 0 deletions valid-palindrome/yuhyeon99.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function(s) {
const regexp = /[^a-z0-9]/g;
s = s.toLowerCase();
s = s.replaceAll(regexp, "");

return s === [...s].reverse().join('');
};