Skip to content

Commit 2f9c670

Browse files
Merge pull request #1959 from CodingTestStudy2/황은지
[황은지] Day02
2 parents 0dd8c21 + 6759880 commit 2f9c670

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
var countMonobit = function(n) {
6+
// 0은 꼭 포함, 나머지는 전부 1로만 이루어짐
7+
let count=1;
8+
const binary=n.toString(2);
9+
count+=(binary.length-1);
10+
if(!binary.includes("0")) count+=1;
11+
12+
return count;
13+
};

0 commit comments

Comments
 (0)