https://leetcode.com/problems/longest-palindrome/

public class Solution {
public int longestPalindrome(String s) {
char []charr = s.toCharArray();
Arrays.sort(charr);
int result = 0;
for (int i=0; i<charr.length; i++) {
if (i==charr.length-1) {
break;
}
if (charr[i] == charr[i+1]) {
result += 2;
i++;
}
}
if (result < charr.length) {
result++;
}
return result;
}
}

longest-palindrome的更多相关文章

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

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

  2. 409. Longest Palindrome

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

  3. LeetCode 409 Longest Palindrome

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

  4. LeetCode Longest Palindrome

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

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

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

  6. 24. leetcode 409. Longest Palindrome

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

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

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

  8. 【leetcode】409. Longest Palindrome

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

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

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

  10. Longest palindrome subsequence

    A palindrome is a nonempty string over some alphabet that reads the same forwardand backward. Exampl ...

随机推荐

  1. ceph笔记(一)

    一.ceph概述本质上是rados:可靠的.自动的.分布式对象存储特性:高效性(大型的网络raid,性能无限接近raid).统一性(支持文件存储.块存储.对象存储).可扩展性数据库的一个弱点:查表ce ...

  2. ImportError: No module named yum

    [root@localhost]# yum-complete-transactionTraceback (most recent call last):  File "/usr/sbin/y ...

  3. 洛谷P1726 上白泽慧音 [Tarjan]

    题目传送门 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...

  4. Am335x SD卡 启动制作

    1.网上下载DiskGenius(分区工具) 2.将4Gsd卡分区3个,boot,rootfs,user 3.boot分区大概在62M左右如图所示 将编译好的MLO.u-boot.img.uEnv.t ...

  5. Qt Installer Framework实战

    Qt Installer Framework是Qt发布的安装程序支持框架,只需要简单的配置就可以生成安装文件,同时可以通过javascript脚本来定制安装过程. 目录结构 config packag ...

  6. javascript类型系统

    前面的话 除了对象之外,数组Array类型可能是javascript中最常用的类型了.而且,javascript中的数组与其他多数语言中的数组有着相当大的区别.本文将介绍javascript中的数组A ...

  7. FastReport.Net使用:[15]富文本控件使用

    富文本(Rich Text)控件用于显示Rtf格式的文本. 认识富文本编辑窗体 1.下图就是富文本的编辑窗体,乍一看就像Word一样,不过功能没有Word强大了.具体功能就不一一介绍了,用个Word的 ...

  8. hashMap原理剖析

    在日常开发中,hashMap应该算是比较常用的一个类了,今天就来学习一下hashMap的实现原理. 概念 1.什么时hash? 书面定义:就是把一个不固定长度的二进制值映射成一个固定长度的二进制值. ...

  9. HDU 3790最短路径问题 [最短路最小花费]

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3790] 最短路径问题 Time Limit: 2000/1000 MS (Java/Others)  ...

  10. [BZOJ 4719] 天天爱跑步

    Link: BZOJ 4719 传送门 Solution: 感觉求LCA又有了新姿势啊:$Tarjan$离线$O(n+m)$ 每次递归返回时将子树和父节点合并,如果询问节点已访问过则LCA就是已合并的 ...