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
给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。
在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。
Input: "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.
The text was updated successfully, but these errors were encountered:
/** * @param {string} s * @return {number} */ var longestPalindrome = function(s) { const cache = new Map(); let result = 0; let hasSingleLetter = false; for (let i = 0; i < s.length; i++) { cache.set(s[i], (cache.get(s[i]) || 0) + 1); } cache.forEach((letter) => { result += (letter >> 1) * 2; if (letter % 2 === 1) { hasSingleLetter = true; } }); return result + (hasSingleLetter ? 1 : 0); };
function longestPalindrome(s: string): number { const cache: Map<string, number> = new Map(); let result = 0; let hasSingleLetter = false; for (let i = 0; i < s.length; i++) { cache.set(s[i], (cache.get(s[i]) || 0) + 1); } cache.forEach((letter) => { result += (letter >> 1) * 2; if (letter % 2 === 1) { hasSingleLetter = true; } }); return result + (hasSingleLetter ? 1 : 0); };
Sorry, something went wrong.
No branches or pull requests
409. Longest Palindrome
给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。
在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。
Example
Note
The text was updated successfully, but these errors were encountered: