leetcode 477. Total Hamming Distance | 477. 汉明距离总和
生活随笔
收集整理的這篇文章主要介紹了
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. 汉明距离总和的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode 834. Sum of
- 下一篇: 478. Generate Random