728x90
set 자료형의 intersection 사용
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
return list(set(nums1).intersection(nums2))
difference 도 차집합 구할 떄 사용 가능
list(set(nums1).difference(nums2))
728x90
'Leetcode' 카테고리의 다른 글
[LeetCode] Valid Perfect Square 파이썬 (Binary Search, +Lower Bound) (0) | 2021.04.14 |
---|---|
[LeetCode] Intersection of Two Arrays II 파이썬 (defaultdict, Counter, extend) (0) | 2021.04.13 |
[LeetCode] Reverse Vowels of String 파이썬 (swap, two pointer) (0) | 2021.04.13 |
[LeetCode] Reverse String 파이썬 (in-place, list.reverse()) (0) | 2021.04.12 |
[LeetCode] Word Pattern 파이썬 (isomorphic, contract mapping) (0) | 2021.04.12 |
댓글