Longest Common Prefix

class Solution {
public:
    string longestCommonPrefix(vector<string> &strs) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int size = strs.size();
        if(size == 0)
        return "";
        if(size == 1)
        return strs[0];
        int i = 0;
        string result = "";
        while(1)
        {
            if(strs[0][i] == '')
            break;
            char temp = strs[0][i];
            int j;
            for( j = 1; j < size;j++)
            {
                if(temp != strs[j][i])
                break;
            }
            if(j!=size)
            break;
            i++;
            result+=temp;
        }
        return result;
    }
};

原文地址:https://www.cnblogs.com/727713-chuan/p/3306131.html