My solution for O(n2) time in Swift


#1
func longestCommonPrefix(_ A: inout [String]) -> String {

    if A.isEmpty {
        return ""
    }
    if A.count == 1 {
        return A[0]
    }
        
    var subStringArray = [Character]()
    
    let a = Array(A[0])
    let b = Array(A[1])
    
    var j = 0
    while j < a.count && j < b.count {
        if a[j] == b[j] {
            subStringArray.append(a[j])
        } else {
            break
        }
        j += 1
    }
    for i in 2..<A.count {
        let c = Array(A[i])
        
        j = 0
        while j < c.count && j < subStringArray.count {
            
            if c[j] != subStringArray[j] {
                break
            }
            j += 1
        }
        
        while j < subStringArray.count {
            subStringArray.remove(at: j)
        }
    }
    return String(subStringArray)
}