mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 23:09:36 +03:00
Added solution to Leetcode Problem 461
This commit is contained in:
parent
5a6ed8e245
commit
1f88545538
@ -48,6 +48,7 @@ LeetCode
|
||||
|389|[Find the Difference](https://leetcode.com/problems/find-the-difference/) | [C](./src/389.c)|Easy|
|
||||
|404|[Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/) | [C](./src/404.c)|Easy|
|
||||
|442|[Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/) | [C](./src/442.c)|Medium|
|
||||
|461|[Hamming Distance](https://leetcode.com/problems/hamming-distance/) | [C](./src/461.c)|Easy|
|
||||
|509|[Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) | [C](./src/509.c)|Easy|
|
||||
|520|[Detect Capital](https://leetcode.com/problems/detect-capital/) | [C](./src/520.c)|Easy|
|
||||
|561|[Array Partition I](https://leetcode.com/problems/array-partition-i/) | [C](./src/561.c)|Easy|
|
||||
|
10
leetcode/src/461.c
Normal file
10
leetcode/src/461.c
Normal file
@ -0,0 +1,10 @@
|
||||
int hammingDistance(int x, int y){
|
||||
int difference = x ^ y;
|
||||
int TotalBits = sizeof(difference)*8;
|
||||
int i, distance = 0;
|
||||
for(i = 0; i < TotalBits; i++) {
|
||||
if(difference & (UINT32_C(1) << i))
|
||||
distance += 1;
|
||||
}
|
||||
return distance;
|
||||
}
|
Loading…
Reference in New Issue
Block a user