My LeetCode grinding. Trying to do a problem a day.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.c 322B

123456789101112131415161718192021
  1. #include <stdio.h>
  2. int countBits(int);
  3. int hammingDistance(int x, int y) {
  4. return countBits(x ^ y);
  5. }
  6. int countBits(int v) {
  7. int c;
  8. for (c = 0; v; v >>= 1) {
  9. c += v & 1;
  10. }
  11. return c;
  12. }
  13. int main() {
  14. printf("Expected: 2\n");
  15. printf("Got: %d\n", hammingDistance(1, 4));
  16. return 0;
  17. }