Skip to content

문제 해설 추가 #99

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 2 commits into from
Sep 7, 2022
Merged
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
18 changes: 18 additions & 0 deletions level-2/3-x-n-타일링.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//https://github.com/codeisneverodd/programmers-coding-test
//더 좋은 풀이가 존재할 수 있습니다.
//정답 1 - codeisneverodd
function solution(n) {
if (n % 2 !== 0) return 0;

const getCount = n => {
const k = n / 2;
const count = [3, 11, ...Array(k - 2)];
const divider = 1000000007;
for (let i = 2; i < k; i++) {
count[i] = (4 * count[i - 1] - count[i - 2] + divider) % divider;
}
return count[count.length - 1];
};

return getCount(n);
}
20 changes: 20 additions & 0 deletions level-2/이진-변환-반복하기.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//https://github.com/codeisneverodd/programmers-coding-test
//더 좋은 풀이가 존재할 수 있습니다.
//정답 1 - codeisneverodd
function solution(s) {
const removeZero = s => {
const removed = s
.split('')
.filter(n => n !== '0')
.join('');
return { removed, count: s.length - removed.length };
};

const convertToBinary = (s, turnCount, removedCount) => {
if (s === '1') return [turnCount, removedCount];
const { removed, count } = removeZero(s);
return convertToBinary(removed.length.toString(2), turnCount + 1, removedCount + count);
};

return convertToBinary(s, 0, 0);
}