Java | HashSet | Beats > 93% | Simple code
Complexity\n- Time complexity: O(m+n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(max(m,n))\n Add your space complexity here, e.g. O(n)
# Complexity\n- Time complexity: $$O(m+n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(max(m,n))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n  public List<List<Integer>> findDifference(int[] nums1, int[] nums2) {\n    var set1 = new HashSet<Integer>();\n    var set2 = new HashSet<Integer>();\n    var common = new HashSet<Integer>();\n\n    for (var n : nums1)\n      set1.add(n);\n\n    for (var n : nums2) {\n      if (set1.contains(n)) {\n        set1.remove(n);\n        common.add(n);\n      } else if (!common.contains(n)) {\n        set2.add(n);\n      }\n    } \n    return new ArrayList<>() {{\n      add(new ArrayList<>(set1));\n      add(new ArrayList<>(set2));\n    }};\n  }\n}\n```\nIf you like my solution, please upvote it!
['Array', 'Hash Table', 'Java']