My LeetCode grinding. Trying to do a problem a day.
Vous ne pouvez pas sélectionner plus de 25 sujets
Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
12345678910111213141516 |
- #include <stdio.h>
-
- int findComplement(int num) {
- int mask = num;
- mask |= mask >> 1;
- mask |= mask >> 2;
- mask |= mask >> 4;
- mask |= mask >> 8;
- mask |= mask >> 16;
- return ~num & mask;
- }
-
- int main() {
- printf("Expected: 2\n");
- printf("Got: %d\n", findComplement(5));
- }
|