本文主要是介绍leetcode 477. Total Hamming Distance | 477. 汉明距离总和,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目
https://leetcode.com/problems/total-hamming-distance/
题解
class Solution {public int totalHammingDistance(int[] nums) {int N = nums.length;int[] count = new int[32];for (int n : nums) {for (int i = 0; i < 32; i++) {count[i] += (n >> i) & 1;}}int result = 0;for (int c : count) {result += c * (N - c);}return result;}
}
这篇关于leetcode 477. Total Hamming Distance | 477. 汉明距离总和的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!