728x90
난이도 : Medium
길이가 n으로 같은 행렬 2개 A,B가 있는데, C[i]는 A[0:i]와 B[0:i]에서 어떤 요소가 같은지 찾으라는 문제
class Solution:
def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]:
n = len(A)
C = []
for i in range(n):
a = list(set(A[0:i+1]) & set(B[0:i+1]))
C.append(len(a))
return C
리스트 A와 B를 교집합한 값을 C 행렬 뒤에다가 하나씩 붙여넣기했다.
Runtime : 52ms (16.41%)
Memory : 17.58MB (49.74%)
728x90
'코딩 공부 > Leetcode' 카테고리의 다른 글
[Python] 1089. Duplicate Zeros (0) | 2025.01.16 |
---|---|
[Python] 1769. Minimum Number of Operations to Move All Balls to Each Box (0) | 2025.01.15 |
[Python] 3223. Minimum Length of String After Operations (0) | 2025.01.14 |
[Python] 1408. String Matching in an Array (0) | 2025.01.13 |
[Python] 2116. Check if a Parentheses String Can Be Valid (0) | 2025.01.12 |