Skip to content

Commit c832197

Browse files
Merge pull request codeisneverodd#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
+17
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)