4ms C++ solution


  • 0
    C
    class Solution {
    public:
    	string longestCommonPrefix(vector<string>& strs) {
    		if (strs.empty()) return "";
    		string res="";
    		int i = 0;
    		while (true)
    		{
    			for (int j = 0; j < strs.size(); j++)
    				if (i == strs[j].size() || strs[j][i] != strs[0][i])
    					return res;
    			res +=strs[0][i];
    			i++;
    		}
    	}
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.