LeetCode #14 最长公共前缀

class Solution {
public:
    string longestCommonPrefix(vector& strs) {
        if (strs.size()==0){
            return "";
        }
        string ans;
        int i=0;
        int j;
        while(i=strs[j].size()||strs[j][i]!=strs[0][i]){
                    return ans;
                }
                j++;
            }
            ans.push_back(strs[0][i]);
            i++;
        }
        return ans;
    }
};

你可能感兴趣的:(LeetCode #14 最长公共前缀)