Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
if(0 == strs.size())
return "";
unsigned maxLen = strs[0].size();
for(int i = 1; i < strs.size(); ++i){
maxLen = min(maxLen, strs[i].size());
for(int j = 0; j < maxLen; ++j){
if(strs[0].at(j) != strs[i].at(j)){
maxLen = j;
break;
}
}
}
return strs[0].substr(0, maxLen);
}
};