Easy-41
来源:互联网 发布:mac系统常用软件下载 编辑:程序博客网 时间:2024/04/28 18:25
leetcode 409. 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.
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:7Explanation:One longest palindrome that can be built is "dccaccd", whose length is 7.
AC:
int longestPalindrome(char* s) {
int len=strlen(s);
int result=0;
int sum=0;
if(len==0)
{
return 0;
}
if(len==1)
{
return 1;
}
int a[52]={0};
for(int i=0;i<len;i++)
{
if(s[i]>='a'&&s[i]<='z')
{
a[s[i]-'a']++;
}
else
{
a[s[i]-'A'+26]++;
}
}
for(int i=0;i<52;i++)
{
if(a[i]>1)
{
result+=a[i]/2;
a[i]=a[i]%2;
}
sum+=a[i];
}
result*=2;
if(sum>=1)
{
return result+1;
}
return result;
}
- Easy-41
- easy
- Easy
- Easy-题目41:219. Contains Duplicate II
- Easy Plugs
- easy problem
- So Easy!
- so easy
- easy explorer
- Easy Explore
- Easy Task
- Easy Task
- Easy CHM
- HDU2699+Easy
- HDU4648+Easy
- Easy billiards
- Easy STL
- easy connect
- eclipse中tomcat的add and remove找不到项目
- jquery的this与$(this)的区别
- escape,encodeURI,encodeURIComponent方法使用
- docker中宿主机与容器(container)互相拷贝传递文件的方法
- HDU 6030 Happy Necklace
- Easy-41
- 正则表达式各种符号的解释
- Ubuntu16下Eclipse中启动Tomcat浏览器无法访问主页
- 399. Evaluate Division
- “J.U.C”:ReentrantLock之二lock方法分析
- 树上dp的基本东西
- iOS 虚线圆
- Java利用OpenOffice将word等office文档转换成PDF
- 539UVA卡坦岛