bumpsoo 2025-01-14 20:41:35 +09:00
parent 1d6dfd4f8d
commit 13d43f7baf

View file

@ -0,0 +1,18 @@
# 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