国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

LEETCODE--Longest Palindrome

2019-11-14 09:23:26
字體:
供稿:網(wǎng)友

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example “Aa” is not considered a palindrome here. Note: Assume the length of given string will not exceed 1,010. Example: Input: “abccccdd”

Output: 7

Explanation: One longest palindrome that can be built is “dccaccd”, whose length is 7.

class Solution {public: int longestPalindrome(string s) { int letters[52] = {0}; for(int i = 0; i < s.length(); i++){ if((s[i] - 'Z') > 0){ letters[26 + (s[i] - 'a')]++; }else{ letters[s[i] - 'A']++; } } int odd = 0; int sum = 0; for(int j = 0; j < 52; j++){ if(letters[j] % 2 != 0){ odd = 1; sum += (letters[j] - 1); }else{ sum += letters[j]; } } if(odd == 1) return sum + 1; else return sum; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁夏| 桃园县| 湖州市| 远安县| 财经| 海晏县| 威远县| 柘城县| 襄城县| 石泉县| 葫芦岛市| 息烽县| 尼木县| 高邑县| 揭阳市| 炎陵县| 洪泽县| 巧家县| 花垣县| 邵阳县| 吉木乃县| 台东市| 独山县| 荣成市| 陆良县| 墨玉县| 金乡县| 上饶市| 南郑县| 车险| 宿松县| 桂阳县| 当阳市| 荆州市| 彝良县| 上犹县| 彩票| 平陆县| 岳池县| 罗江县| 阿拉尔市|