stringlongestCommonPrefix(vector<string>& strs){ string s = ""; int size = strs.size(); if (size == 0) return s; int* lens = newint[size]; int min= strs[0].length(); for (int i = 1; i < size; ++i) { lens[i] = strs[i].length(); if (lens[i] < min) min = lens[i]; } char ch; bool flag = true; for (int i = 0; i < min && flag; ++i)//字符串长度 { ch = strs[0][i]; for (int j = 0; j < size; ++j)//遍历每个字符串 { if (strs[j][i] != ch) { flag = false; break; } } if (flag) s = s + ch; } return s; }