This commit is contained in:
parent
1d6dfd4f8d
commit
13d43f7baf
1 changed files with 18 additions and 0 deletions
18
medium/find_the_prefix_common_array_of_two_arrays.py
Normal file
18
medium/find_the_prefix_common_array_of_two_arrays.py
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue