class Solution { public: /** * * @param strs string字符串vector * @return string字符串 */ string longestCommonPrefix(vector& strs) { // write code here if(strs.empty()) return ""; int m = strs.size(); int n = strs[0].size(); string s = strs[0]; for(int i = 0; i < n; i ++ ) { char c = strs[0][i]; for(int j = 1; j < m; j ++ ) { if(strs[j][i] != c || strs[j].size() == i) { return s.substr(0, i); } } } return strs[0]; } };