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:

  1. Input:
  2. "abccccdd"
  3.  
  4. Output:
  5. 7
  6.  
  7. Explanation:
  8. One longest palindrome that can be built is "dccaccd", whose length is 7.
  1. package leetcode.easy;
  2.  
  3. public class LongestPalindrome {
  4. public int longestPalindrome(String s) {
  5. int[] count = new int[128];
  6. for (char c : s.toCharArray()) {
  7. count[c]++;
  8. }
  9.  
  10. int ans = 0;
  11. for (int v : count) {
  12. ans += v / 2 * 2;
  13. if (ans % 2 == 0 && v % 2 == 1) {
  14. ans++;
  15. }
  16. }
  17. return ans;
  18. }
  19.  
  20. @org.junit.Test
  21. public void test() {
  22. System.out.println(longestPalindrome("abccccdd"));
  23. }
  24. }

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. ES6--默认参数表达式,参数变动

    今天发现个有趣的问题,传入默认参数是个函数时,自定义参数回变动. 先上例子再说 let value = 5; function getValue() { return value++; } funct ...

  2. beta版本——第五次冲刺

    第五次冲刺 (1)SCRUM部分☁️ 成员描述: 姓名 李星晨 完成了哪个任务 界面优化 花了多少时间 2h 还剩余多少时间 2h 遇到什么困难 没有 这两天解决的进度 2/2 后续两天的计划 完成文 ...

  3. Beta版本冲刺及发布成绩汇总

    作业要求 1.作业内容: 作业具体要求及评分标准的链接 2.评分细则 1.冲刺内容占30分. (1)  各成员两天完成的工作,以及后续两天的任务安排(表格的形式记录各个成员这两天的工作,表格内容参考S ...

  4. 【Selenium-WebDriver实战篇】ScreenRecorder的实际输出路径,自己的解决方案

    ==================================================================================================== ...

  5. Spring源码窥探之:声明式事务

    1. 导入驱动,连接池,jdbc和AOP的依赖 <!-- c3p0数据库连接池 --> <dependency> <groupId>c3p0</groupId ...

  6. 使用eclipse-hadoop插件无法再eclipse操作(上传、删除文件)

    再conf中的hdfs-site.xml添加如下配置: <property><name>dfs.permissions</name><value>fal ...

  7. 自动化发送邮件之SMTP

    一.思路 1.若是QQ邮箱需要在设置-账户里面开启服务 2.在python中smtplib库是专门用来处理邮件 3.自动化邮件发送实操 a.要处理的邮件主题,寄件人,收件人,邮件正文,附件, b.邮件 ...

  8. keras中to_categorical()函数解析

    from keras.utils.np_utils import * # 类别向量定义 b = [0, 1, 2, 3, 4, 5, 6, 7, 8] # 调用to_categorical将b按照9个 ...

  9. 按值传递与按值引用详解(java版)

    http://blog.csdn.net/zzp_403184692/article/details/8184751

  10. WinDbg常用命令系列---显示数字格式化.formats

    .formats (Show Number Formats) .formats命令在当前线程和进程的上下文中计算表达式或符号,并以多种数字格式显示它. .formats expression 参数: ...