此篇文章為我的解題紀錄,程式碼或許並不是很完善

Leetcode - 349. Intersection of Two Arrays

解題思路

一一檢查第一個陣列內的所有元素是否有在第二個陣列裡

我滴程式碼

1
2
3
4
5
6
7
8
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
ans = []
for i in nums1:
if (i in nums2 and i not in ans):
ans.append(i)

return ans