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. Oid 类

    参考地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.oid?redirectedfrom=MSD ...

  2. Python常用标准库函数

    math库: >>> import math >>> dir(math) ['__doc__', '__loader__', '__name__', '__pack ...

  3. docker postgresql 数据库

    1. 使用docker 镜像 获取镜像:docker pull postgres:9.4 启动: docker run --name postgres1 -e POSTGRES_PASSWORD=pa ...

  4. Spring事务源码梳理

    通过注解@EnableTransactionManagement中的@Import(TransactionManagementConfigurationSelector.class)给容器中导入了两个 ...

  5. insmod: ERROR: could not insert module dm-snapshot.ko: Unknown symbol in module

    下面方法成功的前提是你的mod和你的操作系统版本是匹配的,也就是说你的mod之前成功过.说个多余的提示,mod在/lib/modules目录里面 insmod: ERROR: could not in ...

  6. 实现:调用API函数ShowWindow()来隐藏窗口

    只需要将相应代码复制即可. 代码如下: #include <iostream> #include <windows.h> int main() { HWND hDos; //声 ...

  7. php生成pdf,php+tcpdf生成pdf, php pdf插件

    插件例子:https://tcpdf.org/examples/ 下载tcpdf插件: demo // Include the main TCPDF library (search for insta ...

  8. 每日Android一问等你来解答-什么是Activity的生命周期?

    关注我,每天都有优质技术文章推送,工作,学习累了的时候放松一下自己. 本篇文章同步微信公众号 欢迎大家关注我的微信公众号:「醉翁猫咪」 什么是Activity的生命周期? 生命周期: 对于生命周期我们 ...

  9. USACO 2009 Open 干草塔 Tower of Hay

    USACO 2009 Open 干草塔 Tower of Hay Description 为了调整电灯亮度,贝西要用干草包堆出一座塔,然后爬到牛棚顶去把灯泡换掉.干草 包会从传送带上运来,共会出现N包 ...

  10. mysql avg()函数,获取字段的平均值

    mysql> select * from table1; +----------+------------+-----+---------------------+ | name_new | t ...