0%
思路:暴力
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| class Solution { public: string longestCommonPrefix(vector<string>& strs) { int i,j; string s=""; if(strs.size()==0) return s; for(i=0;i<strs[0].length();i++) { for(j=1;j<strs.size();j++) { if(strs[j][i]!=strs[0][i]) return s; } s+=strs[0].substr(i,1); } return s; } };
|