409. Longest Palindrome

Easy

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.
package leetcode.easy;

public class LongestPalindrome {
public int longestPalindrome(String s) {
int[] count = new int[128];
for (char c : s.toCharArray()) {
count[c]++;
} int ans = 0;
for (int v : count) {
ans += v / 2 * 2;
if (ans % 2 == 0 && v % 2 == 1) {
ans++;
}
}
return ans;
} @org.junit.Test
public void test() {
System.out.println(longestPalindrome("abccccdd"));
}
}

LeetCode_409. Longest Palindrome的更多相关文章

  1. 【leetcode】409. Longest Palindrome

    problem 409. Longest Palindrome solution1: class Solution { public: int longestPalindrome(string s) ...

  2. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  3. 409. Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  4. LeetCode 409 Longest Palindrome

    Problem: Given a string which consists of lowercase or uppercase letters, find the length of the lon ...

  5. LeetCode Longest Palindrome

    原题链接在这里:https://leetcode.com/problems/longest-palindrome/ 题目: Given a string which consists of lower ...

  6. 每天一道LeetCode--409 .Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  7. 24. leetcode 409. Longest Palindrome

    409. Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the le ...

  8. [Swift]LeetCode409. 最长回文串 | Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  9. [LeetCode&Python] Problem 409. Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

随机推荐

  1. Cloudera Certified Associate Administrator案例之Test篇

    Cloudera Certified Associate Administrator案例之Test篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.准备工作(将CM升级到&qu ...

  2. react中IOS手机里面两个input同时存在时,聚焦focus失效解决办法

    最近在做webapp搜索功能时,用到两个input同时存在时,轻点input聚焦时,ios手机软键盘弹起又失效,一直在寻找合理的解决办法,现在最简单的总结回顾: <一>bug显示 < ...

  3. 《老子》是帝王术,提倡复古,崇拜圣人,主张愚民,甘居下流,不争上游:4星|李零《人往低处走:<老子>天下第一》

    ​​“ 俗话说,“人往高处走,水往低处流”.<老子>正好相反,它强调的是作“天下谷”.“天下溪”.“天下之牝”,甘居下流,不争上游(第28和第61章).司马谈说,道家的特点是“去健羡,绌聪 ...

  4. centos服务器上git clone下载加速

    最近在服务器上直接git clone github上的仓库,下载速度只有十几KB,简直不要太慢! 网上搜了一些加速的,自己于是写了下面的总结. 1. nslookup命令 如果执行这个命令找不到,请先 ...

  5. Jquery的$(document).click() 在iphone手机上失效的问题

    click事件和 touchstart事件共存 安卓IOS手机都适用 $(document).on("click touchstart", ".demo", f ...

  6. AST11103 Problem Solving

    AST11103 Problem Solving with Programming SkillsAdditional Individual Assignment: Min-Game Programmi ...

  7. Refactoring open source business models

    https://opensource.com/business/16/4/refactoring-open-source-business-models They say you never forg ...

  8. ImportError: cannot import name HTTPSHandler

    原因在于openssl,openssl-devel两个文件包未正确安装.用下来的命令来安装: 2 yum install openssl -y yum install openssl-devel -y ...

  9. tornado处理跨域问题

    报错信息一: Access to XMLHttpRequest at 'http://localhost:4445/api/v/getmsg' from origin 'http://localhos ...

  10. 保护 SSH 的三把锁

    转自:https://www.ibm.com/developerworks/cn/aix/library/au-sshlocks/index.html 简介 如果需要远程访问计算机并启用了 Secur ...