Open arshelia opened 4 years ago
var longestCommonPrefix = function(strs) {
if(!strs.length) return "";
var str = strs[0];
for(let i = 0; i < str.length; i++){
var temp = str.charAt(i);
for(let j = 1; j < strs.length; j++){
if(i > strs[j].length || strs[j].charAt(i) !== temp){
return str.substr(0, i);
}
}
}
return str;
};
题目
链接: https://leetcode-cn.com/problems/longest-common-prefix/