Skip to content

Commit ac19711

Browse files
Merge pull request #1957 from CodingTestStudy2/염혜정
[염혜정] Day02
2 parents 90432b5 + 2a69ecf commit ac19711

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// 0을 제외하고 1, 11, 111, 1111... (2^1 - 1, 2^2 - 1, 2^3 -1)
2+
// o(log n)
3+
4+
class Solution {
5+
public int countMonobit(int n) {
6+
int cnt = 1; // 0은 무조건 포함
7+
int num = 1;
8+
while (num <= n) {
9+
cnt++;
10+
num = num * 2 + 1;
11+
}
12+
return cnt;
13+
}
14+
}

0 commit comments

Comments
 (0)