Basic Set Operations || 96% Beats || Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \nAs we have to find distinct numbers we can use set data structure.\n# Approach\n Descri
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs we have to find ***distinct*** numbers we can use ***set*** ***data*** ***structure***.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**method1** Set Operations\nHere we have used basic set operations.\n\n**method2** Hashing\nIterated over the lsit and added to set and append the distinct elements to the answer.\n\nHope you get this or comment for any clarification.\n\nAnd all set:)\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(len(nums1) + len(nums2))\n\n# Code\n```\nclass Solution:\n    def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:\n        set1 = set(nums1)\n        set2 = set(nums2)\n\n        difference1 = list(set1 - set2)\n        difference2 = list(set2 - set1)\n\n        answer = [difference1, difference2]\n\n\n        return answer\n```\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n1 + n2)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(len(nums1) + len(nums2))\n# Code\n```\nclass Solution:\n    def findDifference(self, nums1: List[int], nums2: List[int]) -> List[List[int]]:\n        set1 = set(nums1)\n        set2 = set(nums2)\n        answer = []\n\n        l = set()\n\n        for i in nums1:\n            if i not in set2:\n                l.add(i)\n        answer.append(l)\n\n        l = set()\n\n        for i in nums2:\n            if i not in set1:\n                l.add(i)\n        answer.append(l)\n\n        return answer\n```\n\n\n\n\n
['Hash Table', 'Python3']