We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 简单
Related Topics: 字符串
编写一个函数来查找字符串数组中的最长公共前缀。
如果不存在公共前缀,返回空字符串 ""。
""
示例 1:
输入:strs = ["flower","flow","flight"] 输出:"fl"
示例 2:
输入:strs = ["dog","racecar","car"] 输出:"" 解释:输入不存在公共前缀。
提示:
1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i]
Language: JavaScript
/** * @param {string[]} strs * @return {string} */ var longestCommonPrefix = function(strs) { let re = strs[0] || '' if (strs.length === 1) return strs[0] for (let i = 1; i < strs.length; i++) { while (strs[i].slice(0, re.length) !== re) { re = re.slice(0, re.length - 1) } } return re };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
14. 最长公共前缀
Description
Difficulty: 简单
Related Topics: 字符串
编写一个函数来查找字符串数组中的最长公共前缀。
如果不存在公共前缀,返回空字符串
""
。示例 1:
示例 2:
提示:
1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i]
仅由小写英文字母组成Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: