find-the-prefix-common-array-of-two-arrays 1.0.0
Find the Prefix Common Array of Two Arrays
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

vector< int > findThePrefixCommonArray (vector< int > &A, vector< int > &B)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ findThePrefixCommonArray()

vector< int > Solution::findThePrefixCommonArray ( vector< int > &  A,
vector< int > &  B 
)
inline

Definition at line 8 of file main.cpp.

9 {
10 set<int> seen;
11 int n = (int)A.size();
12 vector<int> prefix_common(n, 0);
13 for (int i = 0; i < n; ++i)
14 {
15 if (!seen.empty() && seen.find(A[i]) != seen.end())
16 prefix_common[i]++;
17 else
18 seen.insert(A[i]);
19
20 if (!seen.empty() && seen.find(B[i]) != seen.end())
21 prefix_common[i]++;
22 else
23 seen.insert(B[i]);
24
25 if (i != 0)
26 prefix_common[i] += prefix_common[i - 1];
27 }
28 return prefix_common;
29 }

Referenced by main().


The documentation for this class was generated from the following file: