博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
409. Longest Palindrome
阅读量:7013 次
发布时间:2019-06-28

本文共 1056 字,大约阅读时间需要 3 分钟。

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.

难度:easy

题目:给定包含大小写字符组成的字符串,找出用这些字符串所能够成的最长回文串。

思路:字符统计

Runtime: 5 ms, faster than 90.61% of Java online submissions for Longest Palindrome.

Memory Usage: 34.7 MB, less than 100.00% of Java online submissions for Longest Palindrome.

class Solution {    public int longestPalindrome(String s) {        int[] table = new int[255];        for (char c: s.toCharArray()) {            table[c]++;        }        int length = 0, odd = 0;        for (int i = 0; i < 255; i++) {            if (table[i] % 2 > 0) {                odd = 1;            }                        length += table[i] - table[i] % 2;        }                return length + odd;    }}

转载地址:http://wqqtl.baihongyu.com/

你可能感兴趣的文章
jquery获取节点的时候获取包含自己在内的HTML标签
查看>>
android之AlertDialog 点击其它区域自己主动消失
查看>>
小程序 - 提示框
查看>>
Windows 10下安装配置Caffe并支持GPU加速(修改版)
查看>>
CPU profiling
查看>>
feign调用接口session丢失解决方案
查看>>
利用 SPL 快速实现 Observer 设计模式
查看>>
本体感受和演讲能力
查看>>
Spring MVC+Ant+Tomcat+Eclipse最简单的demo
查看>>
JavaScript 对象
查看>>
UrlDecode
查看>>
Quartz.Net在windows服务中的使用
查看>>
一条直线上N个线段所覆盖的总长度
查看>>
sql server 2008学习13 触发器
查看>>
Wix学习整理(5)——安装时填写注册表
查看>>
推荐一个IE6下js调试工具(Companion.JS)
查看>>
Thrift 个人实战--Thrift 网络服务模型
查看>>
利用jQuery实现回收站删除效果
查看>>
php形式的内容被处理
查看>>
清除TFS版本控制信息
查看>>