✅ Simple solution using Set, O(n), Explained and commented
If you\'ll like the explanation, do UpVote :)\n## Algorithm:\n\t\t1. First create 2 sets. Then add nums1 elements to set1, and nums2 to set2.This will give us 2
If you\'ll like the explanation, do **UpVote** :)\n## Algorithm:\n\t\t1. First create 2 sets. Then add nums1 elements to set1, and nums2 to set2.This will give us 2 sets with unique elements only.\n\t\t2. Now,  just iterate to all elements of set1 and add those elements to first sublist of result list, which are not in set2.\n\t\t3. Similarly, iterate to all elements of set2 and add those elements to second sublist of result list, which are not in set1.\n\t\t4. Now, we got our result list.\n\n## Complexity:\n\t\tTime: O(n)  : n is length of input array with bigger length\n\t\tSpace: O(m) : m is size of hashset with bigger length\n\n## Code:\n\tclass Solution {\n\t\tpublic List<List<Integer>> findDifference(int[] nums1, int[] nums2) {\n\t\t\tSet<Integer> set1 = new HashSet<>();                           // create 2 hashsets\n\t\t\tSet<Integer> set2 = new HashSet<>();\n\t\t\tfor(int num : nums1){ set1.add(num); }                         // add nums1 elements to set1\n\t\t\tfor(int num : nums2){ set2.add(num); }                         // add nums2 elements to set2\n\t\t\t\n\t\t\tList<List<Integer>> resultList = new ArrayList<>();             // Initialize result list with 2 empty sublists that we will return\n\t\t\tresultList.add(new ArrayList<>());\n\t\t\tresultList.add(new ArrayList<>());\n\n\t\t\tfor(int num : set1){                                            // just iterate to all elements of set1\n\t\t\t\tif(!set2.contains(num)){ resultList.get(0).add(num); }      // add those elements to first sublist of result list, which are not in set2.\n\t\t\t}\n\t\t\tfor(int num : set2){                                            // just iterate to all elements of set2\n\t\t\t\tif(!set1.contains(num)){ resultList.get(1).add(num); }      // add those elements to first sublist of result list, which are not in set1\n\t\t\t}\n\t\t\treturn resultList;\n\t\t}\n\t}\n\t\nIf you need more explanation or, if got even more optimized way, let me know.\t\nIf you like the explanation, pls **UpVote** :)
['Java']