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. vue-music 关于搜索历史本地存储

    搜索历史 搜索过的关键词 保存在本地存储 localstorage 中,同时多个组件共享搜索历史数据,将数据存到vuex 中,初始值从本地缓存中取得对应key 的值,没有数据默认为空数组 点击搜索关键 ...

  2. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  3. 缩略图信息提取工具vinetto

    缩略图信息提取工具vinetto   在Windows操作系统中,为了方便用户快速浏览图片,系统会自动为每个图片生成预览图.预览图默认保存在同目录的Thumbs.db文件中.当图片文件删除后,Thum ...

  4. zstuoj 4245 KI的斐波那契

    KI的斐波那契 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 550  Solved: 208 Description KI十分喜欢美丽而优雅的斐波那 ...

  5. Yii apache配置站点出现400 Bad Request 的解决方法

    <VirtualHost *:80> ServerName localhost ServerAlias localhost DocumentRoot "/www/frogCms/ ...

  6. Redis学习篇(九)之生存时间

    EXPIRE 设置生存时间,以秒为单位 #### EXPIREAT 设置生存时间,秒时间戳格式 #### PEXPIRE 设置生存时间,毫秒为单位 #### PEXPOREAT 设置生存时间,毫秒时间 ...

  7. Codeforces 493 E.Devu and Birthday Celebration

    \(>Codeforces \space 493\ E.Devu\ and\ Birthday\ Celebration<\) 题目大意 : 有 \(q\) 组询问,每次有 \(n\) 小 ...

  8. Android演示Stack(课下作业)

    Demand 之前活动中误传成别的截图,故在此补充博客 1.使用自己实现的栈构建Android程序,提供用于栈的一个puh按钮和pop按钮,在文本域接收一个字符串作为push的输入,文本区将显示每个操 ...

  9. 【BZOJ-2734】集合选数 状压DP (思路题)

    2734: [HNOI2012]集合选数 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1070  Solved: 623[Submit][Statu ...

  10. Codeforces Round #303 (Div. 2) D. Queue 傻逼题

    C. Woodcutters Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...