Longest Common Prefix - Solution

 ðŸ‘€✌Also Download our app CodeBox  from Play Store for offline use ðŸ‘€✌

SOLUTION

string commonPrefix(vector<string>& strs){
int i = 0;
for( ; i < strs[0].size(); i++){
for(int j = 0 ; j < strs.size() ; j++){
if(i >= strs[j].size() || (strs[j][i] != strs[0][i])){
return strs[0].substr(0,i);
}
}
}
return strs[0].substr(0,i);
}

Comments