LeetCode-Hash-409. Longest Palindrome

来源:互联网 发布:respawn linux 编辑:程序博客网 时间:2024/06/09 16:42

问题:https://leetcode.com/problems/longest-palindrome/
Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
分析:如果字符串中元素出现次数都是偶数,那一定可以构成。如果有出现次数是奇数的,则需要减去出现次数为奇数的,但是中间可以放一个,就再加个1.a的ASCII码是96,A的ASCII码是65.
代码:

这里写图片描述

0 0
原创粉丝点击