?LeetCode刷題實戰(zhàn)409:最長回文串
Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.
Letters are case sensitive, for example, "Aa" is not considered a palindrome here.
示例
輸入:
"abccccdd"
輸出:
7
解釋:
我們可以構(gòu)造的最長的回文串是"dccaccd", 它的長度是 7。
解題
class?Solution?{
????public?int?longestPalindrome(String s)?{
????????int[] count = new?int[58];
????????for?(int?i=0;i????????????count[s.charAt(i)-'A']++;
????????int?ans = 0;
????????for?(int?j:count)
????????????ans+=(j/2)*2;
????????if?(ans < s.length())
????????????ans++;
????????return?ans;
????}
}
LeetCode刷題實戰(zhàn)402:移掉 K 位數(shù)字
LeetCode刷題實戰(zhàn)405:數(shù)字轉(zhuǎn)換為十六進制數(shù)
LeetCode刷題實戰(zhàn)406:根據(jù)身高重建隊列
評論
圖片
表情
