leetcode longest common prefix

bug为while(s1[j]==s2[k]&&j++<s1.size()&&k++<s2.size())这句,一开始写的是while(j++<s1.size()&&k++<s2.size()&&s1[j]==s2[k])

class Solution {
public:
    string longestCommonPrefix(vector<string> &strs)
    {
        if(strs.size()==0)return "";
        int minlen=INT_MAX;
        for(int i=0;i<strs.size()-1;i++)
        {
            if(common(strs[i],strs[i+1])<minlen)
            {
                minlen=common(strs[i],strs[i+1]);
            }
        }
        return strs[0].substr(0,minlen);       
    }
    int common(string s1,string s2)
    {
         int i=0;
         int j=0,k=0;
         while(s1[j]==s2[k]&&j++<s1.size()&&k++<s2.size())
         i++;
         return i;        
    }
};
原文地址:https://www.cnblogs.com/tgkx1054/p/3097509.html