LeetCode_Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings.

  

class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string result="";
if(strs.size() == ) return result ; string first = strs[] ; for(int i = ; i < first.size() ;i++)
{
char c = first[i] ;
for(int j = ; j< strs.size(); j++)
if(i > strs[j].size() - || c != strs[j][i])
return result; result+=c;
} return result ;
}
};
上一篇:wget


下一篇:Python WMI获取Windows系统信息