Skip to content

Commit cfb087f

Browse files
committed
add sol
1 parent 795ec4d commit cfb087f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

leetcode/daily/2657/sol.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/
2+
3+
package main
4+
5+
import "fmt"
6+
7+
func findThePrefixCommonArray(A []int, B []int) []int {
8+
seen := make(map[int]bool) // To track elements seen so far
9+
result := make([]int, len(A))
10+
commonCount := 0
11+
12+
for i := 0; i < len(A); i++ {
13+
if seen[A[i]] {
14+
commonCount++
15+
} else {
16+
seen[A[i]] = true
17+
}
18+
19+
if seen[B[i]] {
20+
commonCount++
21+
} else {
22+
seen[B[i]] = true
23+
}
24+
25+
result[i] = commonCount
26+
}
27+
28+
return result
29+
}
30+
31+
func main() {
32+
A := []int{1, 3, 2, 4}
33+
B := []int{3, 1, 2, 4}
34+
fmt.Println(findThePrefixCommonArray(A, B))
35+
}

0 commit comments

Comments
 (0)