/**
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function (strs) {
if (strs.length === 0) return ''
else if (strs.length === 1) return strs[0]
strs.sort()
let start = strs[0],
end = strs[strs.length - 1],
len = start.length < end.length ? start.length : start.length,
result = ''
for(let i = 0; i < len; i++) {
if (start[i] !== end[i]) break
result += start[i]
}
return result
};
最长公共前缀
最新推荐文章于 2024-11-01 15:19:21 发布