Advertisement
Alexxik

Untitled

Sep 8th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.52 KB | None | 0 0
  1. // 2215. Find the Difference of Two Arrays
  2.  
  3. func findDifference(_ nums1: [Int], _ nums2: [Int]) -> [[Int]] {
  4.     let setOne = Set(nums1)
  5.     let setTwo = Set(nums2)
  6.    
  7.     var firstNo = Set<Int>()
  8.     var secondNo = Set<Int>()
  9.    
  10.     for num in setOne {
  11.        
  12.         if !setTwo.contains(num) {
  13.             firstNo.insert(num)
  14.         }
  15.     }
  16.    
  17.     for num in setTwo {
  18.         if !setOne.contains(num) {
  19.             secondNo.insert(num)
  20.         }
  21.     }
  22.     return [Array(firstNo), Array(secondNo)]
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement