Skip to content

Commit e9ebff0

Browse files
Add 1 solution.
1 parent 3c3cd78 commit e9ebff0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

level-2/점프와-순간-이동.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - codeisneverodd
4+
function solution(n) {
5+
var ans = 0;
6+
while (n > 0) {
7+
if (n % 2 !== 0) {
8+
n = (n - 1) / 2
9+
ans++
10+
} else {
11+
n = n / 2
12+
}
13+
}
14+
return ans;
15+
}

0 commit comments

Comments
 (0)