We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 803dd53 commit 5a1dc53Copy full SHA for 5a1dc53
2657. Find the Prefix Common Array of Two Arrays
@@ -0,0 +1,34 @@
1
+class Solution {
2
+ public int[] findThePrefixCommonArray(int[] A, int[] B) {
3
+ int[] c = new int[A.length];
4
+ for(int i=0;i<A.length;i++){
5
+ boolean found=false;
6
+ for(int j=0;j<B.length;j++){
7
+ if(A[i]==B[j]){
8
+ found=true;
9
+ }
10
+ if(found && j>=i){
11
+ c[j]++;
12
13
14
15
+ return c;
16
17
+}
18
+
19
20
21
22
23
+ int[] freq = new int[A.length+1];
24
+ int count=0;
25
26
+ freq[A[i]]++;
27
+ if(freq[A[i]]==2) count++;
28
+ freq[B[i]]++;
29
+ if(freq[B[i]]==2) count++;
30
+ c[i] = count;
31
32
33
34
0 commit comments