👀✌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
Post a Comment