1 parent 1ab820a commit 6759880Copy full SHA for 6759880
1 file changed
leetcode3/황은지/3827. Count Monobit Integers.js
@@ -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