Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: https://leetcode.com/problems/total-hamming-distance/
- // Solution: https://leetcode.com/problems/total-hamming-distance/discuss/247217/Java-Solutions
- class Solution {
- public int totalHammingDistance(int[] nums) {
- int total = 0;
- for (int i = 0; i < nums.length - 1; i++) {
- for(int j = i + 1; j < nums.length; j++) {
- total += Integer.bitCount(nums[i] ^ nums[j]);
- }
- }
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement