leetcode-longest common prefix

class Solution {
public:
   
    string longestCommonPrefix(vector<string> &strs) 
    {
        int size = strs.size();
        if(size==0)
            return "";
        if(size==1)
            return strs[0];
        string result = "";
        int i,j;
        for(j=0;;j++)
        {
            for(i=0;i<size-1;i++)
            {
                if(strs[i].length()<=j) break;
                if(strs[i][j]==strs[i+1][j])
                    continue;
                else
                    break;
            }
            if(i!=size-1)
                break;
            else
                result += strs[i][j];
        }
        return result;
    }
};

每天早上叫醒你的不是闹钟,而是心中的梦~
原文地址:https://www.cnblogs.com/vintion/p/4116882.html