My Swift solution


  • 0
    Z

    '''

    if nums1.count == 0 || nums2.count == 0 {
        return []
    }
    
    let num1Temp = nums1.sort() {
        return $0 < $1
    }
    
    let num2Temp = nums2.sort(){
        return $0 < $1
    }
    var point1 = 0
    var point2 = 0
    
    var result = [Int]()
    
    while( point1 < num1Temp.count && point2 < num2Temp.count) {
        if num1Temp[point1] < num2Temp[point2] {
            point1 += 1
        }else if num1Temp[point1] > num2Temp[point2]{
            point2 += 1
        }else {
            result.append(num1Temp[point1])
            point1 += 1
            point2 += 1
        }
    }
    
    return result
    }
    

    '''


Log in to reply
 

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