leetcode477
public class Solution {
public int TotalHammingDistance(int[] nums) {
int total = , n = nums.Length;
for (int j = ; j < ; j++)
{
int bitCount = ;
for (int i = ; i < n; i++)
{
bitCount += (nums[i] >> j) & ;
}
total += bitCount * (n - bitCount);
}
return total;
}
}
https://leetcode.com/problems/total-hamming-distance/#/description
leetcode477的更多相关文章
- [Swift]LeetCode477. 汉明距离总和 | Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
随机推荐
- 【Python爬虫学习笔记(2)】正则表达式(re模块)相关知识点总结
1. 正则表达式 正则表达式是可以匹配文本片段的模式. 1.1 通配符 正则表达式能够匹配对于一个的字符串,可以使用特殊字符创建这类模式.(图片来自cnblogs) 1.2 特殊字符的转义 由于在正则 ...
- linux 下 Linux 下char转换为wchar_t 设置本地为utf-8编码 以及wchar 的输入输出
LInux下使用mbstowcs函数可以将char转化为wchar_t函数含义:convert a multibyte string to a wide char string说明: Th ...
- c语言输出4*5的数列?
1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 输出上面的数列,用c实现的代码:<pre lang="c" line=&quo ...
- 同一台电脑的多ssh 配置
转载自:https://w3ctrain.com/2016/03/06/mutiple-ssh-key/ ps:此文基于你已经能够正常的生成sshkey 对于sshkey的功能这里就不多做介绍了,本文 ...
- BZOJ4036:按位或 (min_max容斥&高维前缀和)
Description 刚开始你有一个数字0,每一秒钟你会随机选择一个[0,2^n-1]的数字,与你手上的数字进行或(c++,c的|,pascal 的or)操作.选择数字i的概率是p[i].保证0&l ...
- <context:annotation-config/>,<context:component-scan/>,<mvc:annotation-driven/>区分
链接:http://blog.csdn.net/baple/article/details/16864175 链接:http://blog.csdn.net/Baple/article/details ...
- 使用 Emit 生成 IL 代码
.NET Core/.NET Framework 的 System.Reflection.Emit 命名空间为我们提供了动态生成 IL 代码的能力.利用这项能力,我们能够在运行时生成一段代码/一个方法 ...
- css 样式常用属性
一般的一个DIV的CSS设置属性有:margin,padding,width,height,font-size,text-align,background,float,border 附:< cs ...
- python: find the index of a given value in a list
["foo", "bar", "baz"].index("bar")
- gradle 构建包含源码配置
参考配置: apply plugin: "idea" apply plugin: "groovy" apply plugin: "eclipse&qu ...