leetpycode/medium/find_the_prefix_common_array_of_two_arrays.py

18 lines
554 B
Python

# https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays
from typing import List
class Solution:
def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]:
result = []
count = {}
curr = 0
for i in range(len(A)):
count[A[i]] = count.get(A[i], 0) + 1
if count[A[i]] > 1:
curr += 1
count[B[i]] = count.get(B[i], 0) + 1
if count[B[i]] > 1:
curr += 1
result.append(curr)
return result