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 c832197

Browse files
Merge pull request #38 from le2sky/main
[2022年04月20日] level2 - 2개 이하로 다른 비트, 생성 및 풀이 추가
2 parents 25ba838 + 311aca2 commit c832197

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - le2sky
4+
function solution(numbers) {
5+
const answer = [];
6+
numbers.forEach((num) => {
7+
if (num % 2 == 0) answer.push(num + 1);
8+
else {
9+
let binary = ["0", ...num.toString(2)];
10+
let last = binary.lastIndexOf("0");
11+
binary[last] = "1";
12+
binary[last + 1] = "0";
13+
answer.push(parseInt(binary.join(""), 2));
14+
}
15+
});
16+
return answer;
17+
}

0 commit comments

Comments
(0)

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