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.

from collections import Counter
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: int
"""
c=Counter(s)
if len(c)==1:
return len(s)
ans=0
flag=False
for i in c:
if not flag and c[i]%2==1:
flag=True
ans+=c[i]//2*2
if flag:
ans+=1
return ans

  

[LeetCode&Python] Problem 409. Longest Palindrome的更多相关文章

  1. 【leetcode❤python】409. Longest Palindrome

    #-*- coding: UTF-8 -*- from collections import Counterclass Solution(object):    def longestPalindro ...

  2. [LeetCode&Python] Problem 594. Longest Harmonious Subsequence

    We define a harmonious array is an array where the difference between its maximum value and its mini ...

  3. [LeetCode&Python] Problem 720. Longest Word in Dictionary

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  4. [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...

  5. 【leetcode】409. Longest Palindrome

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

  6. 24. leetcode 409. Longest Palindrome

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

  7. 【LeetCode】409. Longest Palindrome 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:字典统计次数 方法二:HashSet 方法三 ...

  8. [LeetCode] 409. Longest Palindrome 最长回文

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

  9. LeetCode 409 Longest Palindrome

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

随机推荐

  1. 手机验证码JQUERY实现

    <!DOCTYPE html> <html> <head> <script src="http://libs.baidu.com/jquery/1. ...

  2. windows启动/禁用telnet/IIS/ftp/IE等服务

    将需要启动的钩选,将要禁用的取消钩选确定即可:比如我这里要启动telnet客户端. 启动IIS将IIS可承载的Web核心和Internet两大项全钩选上即可,钩多了不影响功能.

  3. listener.ora和tnsnames.ora格式解析

    listener.ora是oracle数据库服务端的监听配置文件,包括协议.IP地址和端口等内容:tnsnames.ora是oracle数据库客户端的连接配置文件,也是对应的协议.IP地址和端口等内容 ...

  4. Java多线程中对CountDownLatch的使用

    CountDownLatch是一个非常实用的多线程控制工具类,称之为“倒计时器”,它允许一个或多个线程一直等待,直到其他线程的操作执行完后再执行.用给定的计数初始化CountDownLatch,其含义 ...

  5. npm node sass 安装报错

    报错为 不能找到python2.7,记得曾经已经安装过python,结果npm install cnpm install npm install node-sass 各种不行,结果在cmd 输入pyt ...

  6. memory prefix out omni,over,out,od,octa ~O

    1● omni 全部 ,到处:     2● over 过度,超过,出去,翻转   3● out 超过,过去,过分, 在~之上,   4● od 逆,倒 :加强 的 意思   5● octa   八

  7. 逆袭之旅DAY16.东软实训.Oracle.序列

    2018-07-12 14:07:44 序列 序列1.创建序列create sequence 序列名 [increment by n] ---步长 [start with n] ---序列的起始值 序 ...

  8. WINDOWS 端口查看

    查看Windows下所有使用的端口 netstat -ano 查看Windows下某一个特定的端口 netstat -ano | find "8080"   查看windows下所 ...

  9. windows 执行bat脚本

    bat脚本中运行另外一个bat脚本 call 命令 call1.bat内容如下 echo running call1 call2.bat内容如下 @echo off echo start call c ...

  10. .clearfix:after(清除浮动)中各个属性及值详细解说

    清除浮动.clearfix:after一词,从事web前端的朋友们对此不会陌生吧,下面为大家介绍的是.clearfix:after中用到的所有属性及值的含义,对此感兴趣的朋友可以参考下哈想,希望对大家 ...