My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
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));
- }
|