最长公共前缀:Write a function to find the longest common prefix string amongst an array of strings.
Solution :
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
if(strs.size()<=0) return "";
if(strs.size()==1) return strs[0];
int s=strs[0].length();
for(int i=1;i<strs.size();i++){
if(s>strs[i].length()) s=strs[i].length();
for(int j=0;j<s;j++){
if(strs[0][j]!=strs[i][j]){
s=j;
break;
}
}
}
if(s<0) return "";
return strs[0].substr(0,s);
}
};