Share my swift code


  • 0
    Z
    class Solution {
    func intersection(nums1: [Int], _ nums2: [Int]) -> [Int] {
        var lessArray = nums1
    var result: [Int] = []
    
    var longerArray = nums2
    if nums1.count > nums2.count {
        lessArray = nums2
        longerArray = nums1
    }
    for vLess in lessArray {
        if longerArray.contains(vLess) {
            if !result.contains(vLess) {
                result.append(vLess)
            }
        }
    }
    return result
    
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.