Easiest Solution ever C++


#1
string Solution::longestCommonPrefix(vector<string> &A) {
    if(A.size() ==1){
        return A[0];
    }
    sort(A.begin(), A.end());
    int n = A.size();
    string first = A[0];
    string second = A[n-1];
    string ans;
    int i=0;
    while(first[i] == second[i]){
        ans.push_back(first[i]);
        i++;
    }
    return ans;
}