Open pwstrick opened 4 years ago
14. 最长公共前缀
/** * @param {string[]} strs * @return {string} */ var longestCommonPrefix = function(strs) { if(!strs.length) return ""; const len = strs.length, chars = []; for(let i=0, strLen=strs[0].length; i<strLen; i++) { for(let j=1; j<len; j++) { if(strs[j][i] != strs[0][i]) { return chars.join(""); } } chars.push(strs[0][i]); } return chars.join(""); };
14. 最长公共前缀