Search
⌘K

Leetcode 477. Total Hamming Distance

Given an array of nonnegative integers, compute the sum of Hamming distances over all pairs of numbers. Key idea: for each bit position, count how many numbers have a 1 and how many have a 0, and add ones * zeros for that bit (summed across all bit positions).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.