Leetcode14._最长公共前缀

class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string s;
s = strs[0];
if(strs.size() == 0)
return "";
if(strs.size() == 1)
return strs[0];
for(int i=0;i<strs.size();i++){
while(strs[i].find(s) != 0)
s=s.substr(0,strs.size()-1);

}
return s;
}
};
 
超时

猜你喜欢

转载自www.cnblogs.com/vocoub/p/11576048.html