Skip to content

Commit f4d5bc9

Browse files
authored
Create 2657. Find the Prefix Common Array of Two Arrays (#688)
2 parents 1a6a72c + 3e7fff8 commit f4d5bc9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
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(), common = 0;
5+
vector<int> result(n), count(n + 1, 0);
6+
7+
for (int i = 0; i < n; ++i) {
8+
if (++count[A[i]] == 2) ++common;
9+
if (++count[B[i]] == 2) ++common;
10+
result[i] = common;
11+
}
12+
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)