[C++] Single line; actually O(1), as opposed to O(number of bits)
OK... I\'m spreading the code over three lines for readability. \uD83D\uDE09\n\nC++\nint minFlips(int a, int b, int c) {\n  return bitset<30>(~(a|b) &  c).count
OK... I\'m spreading the code over three lines for readability. \uD83D\uDE09\n\n```C++\nint minFlips(int a, int b, int c) {\n  return bitset<30>(~(a|b) &  c).count() + // number of bits to flip to 1\n         bitset<30>( a     & ~c).count() + // number of bits to flip to 0 in a\n         bitset<30>( b     & ~c).count();  // number of bits to flip to 0 in b\n}\n```\n\nMost (if not all) solutions claiming **O(1)** runtime seem to still be iterating over all bits. I would argue that\'s actually **O(number of bits)** or **O(log a|b|c)**. I realize that the maximum limit of `a`, `b` and `c` are given in the problem description. But by that reasoning, aren\'t _all_ algorithms O(1)? LeetCode provides constraints for all its recent problems.\n\nBut something like [`bitset<30>(x)::count()`](https://en.cppreference.com/w/cpp/utility/bitset) can be optimized by the compiler. For example, GCC will optimize it to [`__builtin_popcount(x)`](https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fpopcount), which uses a lookup table for each byte, or to a CPU specific instruction like [`POPCNT`](https://en.wikipedia.org/wiki/SSE4#POPCNT_and_LZCNT), which can do a whole integer at once. To enable that instruction for Intel processors, you can add the following line of code:\n\n```C++\n#pragma GCC target ("sse4.2")\n```\n\nThat actually works on LeetCode. Try running `bitset<32>(x)::count()` many times in a loop, both with and without the pragma.
['C']