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

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

LEETCODE--Longest Palindrome

2019-11-11 07:39:05
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 尼木县| 城口县| 舟山市| 绵竹市| 万州区| 区。| 探索| 疏勒县| 宁晋县| 津南区| 隆昌县| 融水| 綦江县| 龙井市| 唐海县| 嵩明县| 灵武市| 兴宁市| 卫辉市| 辽阳县| 嘉善县| 海门市| 崇州市| 大港区| 临澧县| 舞阳县| 盐源县| 渝北区| 富蕴县| 高密市| 措美县| 扬州市| 淮安市| 赫章县| 莎车县| 丰都县| 红桥区| 台湾省| 嘉峪关市| 施秉县| 平凉市|