@@ -0,0 +1,1550 @@
+// 2 pointers solution, runs in O(AlgA + BlgB), space complexity is O(lgA + lgB)%0A// does not include storage for resulting array%0Apublic class Solution %7B%0A  public int%5B%5D intersection(int%5B%5D nums1, int%5B%5D nums2) %7B%0A    Arrays.sort(nums1);%0A    Arrays.sort(nums2);%0A    List%3CInteger%3E lst = new ArrayList%3CInteger%3E();%0A    int i = 0, j = 0;%0A    while (i %3C nums1.length && j %3C nums2.length) %7B%0A      if (nums1%5Bi%5D == nums2%5Bj%5D) %7B%0A        int t = nums1%5Bi%5D;%0A        lst.add(t);%0A        while (i %3C nums1.length && nums1%5Bi%5D == t) i++;%0A        while (j %3C nums2.length && nums2%5Bj%5D == t) j++;%0A      %7D else if (nums1%5Bi%5D %3E nums2%5Bj%5D) %7B%0A        while (j %3C nums2.length && nums2%5Bj%5D %3C nums1%5Bi%5D) j++;%0A      %7D else %7B%0A        while (i %3C nums1.length && nums1%5Bi%5D %3C nums2%5Bj%5D) i++;%0A      %7D%0A    %7D%0A%0A    int%5B%5D res = new int%5Blst.size()%5D;%0A    int index = 0;%0A    for (int elem : lst) %7B%0A        res%5Bindex++%5D = elem;%0A    %7D%0A    return res;%0A  %7D%0A%7D%0A%0A// HashSet based solution, runs in O(A + B), O(max(A, B)) space;%0A// can be reduced to O(min(A, B))%0Apublic class Solution %7B%0A  public int%5B%5D intersection(int%5B%5D nums1, int%5B%5D nums2) %7B%0A    HashSet%3CInteger%3E set = new HashSet%3CInteger%3E();%0A    for (int i = 0; i %3C nums1.length; i++) %7B%0A      set.add(nums1%5Bi%5D);%0A    %7D%0A%0A    List%3CInteger%3E lst = new ArrayList%3CInteger%3E();%0A    for (int i = 0; i %3C nums2.length; i++) %7B%0A      if (set.contains(nums2%5Bi%5D)) %7B%0A        lst.add(nums2%5Bi%5D);%0A        set.remove(nums2%5Bi%5D);%0A      %7D%0A    %7D%0A%0A    int%5B%5D res = new int%5Blst.size()%5D;%0A    int index = 0;%0A    for (int num : lst) %7B%0A      res%5Bindex++%5D = num;%0A    %7D%0A%0A    return res;%0A  %7D%0A%7D%0A

add solution