LeetCode 477. Total Hamming Distance

来源:互联网 发布:淘宝网购物大肥裤子 编辑:程序博客网 时间:2024/05/01 23:25
public class Solution {    public int totalHammingDistance(int[] nums) {        int total = 0;        int l = nums.length;        for (int i = 0; i < 32; i++) {        int count = 0;        for (int j = 0; j < l; j++) count += (nums[j] >> i) & 1;        total += count * (l - count);        }        return total;    }}

0 0
原创粉丝点击