본문 바로가기

IT/코딩테스트

[Leetcode] 2215. Find the Difference of Two Arrays

728x90

https://leetcode.com/problems/find-the-difference-of-two-arrays

 

Find the Difference of Two Arrays - LeetCode

Can you solve this real interview question? Find the Difference of Two Arrays - Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where: * answer[0] is a list of all distinct integers in nums1 which are not present in nums2

leetcode.com

class Solution:
    def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:
        result = [[], []]
        all = list(set(nums1 + nums2))

        for i in all:
            if i in nums1 and i in nums2:
                continue
            elif i in nums1:
                result[0].append(i)
            elif i in nums2:
                result[1].append(i)

        return result
728x90