Skip to content

Commit 8c03598

Browse files
committed
Add C++ solution of problem #2657
1 parent 70fa15a commit 8c03598

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

2657/solution.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> findThePrefixCommonArray(vector<int>& A, vector<int>& B) {
4+
int n = A.size();
5+
vector<int> ans(n);
6+
uint64_t a = 0, b = 0; // hash map
7+
for(int i = 0; i < n; i++) {
8+
a |= (1LL << A[i]);
9+
b |= (1LL << B[i]);
10+
uint64_t c = a & b;
11+
ans[i] = __builtin_popcountll(c);
12+
}
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)