leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

difference-of-two-arraysV2.dart (712B)


      1 //Same as other solution but better because it uses
      2 //sets instead of a map which decreases overhead memory usage.
      3 //Time: 332ms Beats: 80%
      4 //Memory: 151MB Beats: 50%
      5 
      6 class Solution {
      7   List<List<int>> findDifference(List<int> nums1, List<int> nums2) {
      8       Set<int> set1 = {};
      9       Set <int> set2 = {};
     10       for(int i = 0 ; i < nums1.length ; ++i){
     11           set1.add(nums1[i]);
     12       }
     13       for(int i = 0 ; i < nums2.length ; ++i){
     14           set2.add(nums2[i]);
     15       }
     16       for(int i = 0 ; i < nums1.length ; ++i){
     17           set2.remove(nums1[i]);
     18       }
     19       for(int i = 0 ; i < nums2.length ; ++i){
     20           set1.remove(nums2[i]);
     21       }
     22       
     23       return [set1.toList() , set2.toList()];
     24   }
     25 }