Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 66731a7

Browse files
Merge pull request codeisneverodd#99 from codeisneverodd/codeisneverodd
문제 해설 추가
2 parents 3fcc1e3 + 7b369a9 commit 66731a7

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

‎level-2/3-x-n-타일링.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//더 좋은 풀이가 존재할 수 있습니다.
3+
//정답 1 - codeisneverodd
4+
function solution(n) {
5+
if (n % 2 !== 0) return 0;
6+
7+
const getCount = n => {
8+
const k = n / 2;
9+
const count = [3, 11, ...Array(k - 2)];
10+
const divider = 1000000007;
11+
for (let i = 2; i < k; i++) {
12+
count[i] = (4 * count[i - 1] - count[i - 2] + divider) % divider;
13+
}
14+
return count[count.length - 1];
15+
};
16+
17+
return getCount(n);
18+
}

‎level-2/이진-변환-반복하기.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//더 좋은 풀이가 존재할 수 있습니다.
3+
//정답 1 - codeisneverodd
4+
function solution(s) {
5+
const removeZero = s => {
6+
const removed = s
7+
.split('')
8+
.filter(n => n !== '0')
9+
.join('');
10+
return { removed, count: s.length - removed.length };
11+
};
12+
13+
const convertToBinary = (s, turnCount, removedCount) => {
14+
if (s === '1') return [turnCount, removedCount];
15+
const { removed, count } = removeZero(s);
16+
return convertToBinary(removed.length.toString(2), turnCount + 1, removedCount + count);
17+
};
18+
19+
return convertToBinary(s, 0, 0);
20+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /