LeetCode 477. Total Hamming Distance
来源:互联网 发布:许晴 王雪冰 知乎 编辑:程序博客网 时间:2024/06/08 20:47
题目链接:https://leetcode.com/problems/total-hamming-distance/description/
题目大意:给n个数,求所有Hamming距离之和
不知道说啥。。。。。
算是矮子里面拔将军吧。。。。(其实是见识少)
不过也就是初中思维(逃)
以后还是多找点有趣的例子。。。。
class Solution {public: int totalHammingDistance(vector<int>& nums) { int total = 0; int size = nums.size(); for (int bit = 0; bit < 32; ++bit) { int bitCount = 0; for (int i = 0; i < size; ++i) bitCount += (nums[i] >> bit) & 1; total += bitCount * (size - bitCount); } return total; }};
阅读全文
0 0
- LeetCode 477. Total Hamming Distance
- 【Leetcode】477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- [leetcode] 477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- Leetcode-477. Total Hamming Distance
- 【LeetCode】 477. Total Hamming Distance
- [leetcode]477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- [LeetCode]477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- Leetcode: 477. Total Hamming Distance
- leetcode 477. Total Hamming Distance
- leetcode 477. Total Hamming Distance
- LeetCode 477. Total Hamming Distance
- leetcode 477. Total Hamming Distance
- 十二月目标
- Hive的数据模型之桶表
- Java转Python入门之运算与循环
- MongoDB的使用
- 继承ViewGroup
- LeetCode 477. Total Hamming Distance
- SAP Fiori For iOS
- 自定义view实现无线轮播
- webview
- ShoneSharp语言(S#)的设计和使用介绍系列(4)— 入门概述
- 状压dp Survival
- 通过当前时间获取当前所在周的7天的时间
- Hive的数据模型之视图
- IIS发布网站后出现“处理程序"PageHandlerFactory-Integrated"在其模块列表中有一个错误模块”的解决方法