We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dc25880 commit edb93aaCopy full SHA for edb93aa
elements-of-programming-interviews/cpp/count_bits.cc
@@ -1,8 +1,14 @@
1
#include "test_framework/generic_test.h"
2
3
short CountBits(unsigned int x) {
4
- // TODO - you fill in here.
5
- return 0;
+ short count = 0;
+ for (int i = 0; i < sizeof(int) * 8; i++) {
6
+ if (x & 1) {
7
+ count++;
8
+ }
9
+ x >>= 1;
10
11
+ return count;
12
}
13
14
int main(int argc, char* argv[]) {
elements-of-programming-interviews/problem_mapping.js
@@ -2,7 +2,7 @@ problem_mapping = {
"Chapter 04: Primitive Types": {
"4.00 Bootcamp: Primitive Types": {
"C++: count_bits.cc": {
- "passed": 0,
+ "passed": 10001,
"total": 10001
},
"Java: CountBits.java": {
0 commit comments