FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/C++/total-hamming-distance.cpp at master · Monika-R/LeetCode-Solutions · GitHub
Monika-R
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
C++
/
total-hamming-distance.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
17 lines (16 loc) · 403 Bytes
Breadcrumbs
LeetCode-Solutions
/
C++
/
total-hamming-distance.cpp
Copy path
File metadata and controls
17 lines (16 loc) · 403 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
Time: O(n)
//
Space: O(1)
class
Solution
{
public:
int
totalHammingDistance
(vector<
int
>& nums) {
int
result =
0
;
for
(
int
i =
0
; i <
8
*
sizeof
(
int
); ++i) {
vector<
int
>
counts
(
2
);
for
(
const
auto
& num : nums) {
++counts[(num >> i) &
1
];
}
result += counts[
0
] * counts[
1
];
}
return
result;
}
};
Back
|
FazBrowse Home
|
New Git URL