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: 字符串, 动态规划
给你一个字符串 s,找到 s 中最长的回文子串。
s
示例 1:
输入:s = "babad" 输出:"bab" 解释:"aba" 同样是符合题意的答案。
示例 2:
输入:s = "cbbd" 输出:"bb"
提示:
1 <= s.length <= 1000
Language: JavaScript
/** * @param {string} s * @return {string} */ var longestPalindrome = function(s) { let max = '' for (let i = 0; i < s.length; i++) { helper(i, i) helper(i, i+1) } function helper(l, r) { while(l >= 0 && r < s.length && s[l] === s[r]) { l-- r++ } const maxStr = s.slice(l + 1, r - 1 + 1) if (maxStr.length > max.length) max = maxStr } return max };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
5. 最长回文子串
Description
Difficulty: 中等
Related Topics: 字符串, 动态规划
给你一个字符串
s
,找到s
中最长的回文子串。示例 1:
示例 2:
提示:
1 <= s.length <= 1000
s
仅由数字和英文字母组成Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: