[LeetCode&Python] Problem 409. Longest Palindrome
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的更多相关文章
- 【leetcode❤python】409. Longest Palindrome
#-*- coding: UTF-8 -*- from collections import Counterclass Solution(object): def longestPalindro ...
- [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 ...
- [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 ...
- [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...
- 【leetcode】409. Longest Palindrome
problem 409. Longest Palindrome solution1: class Solution { public: int longestPalindrome(string s) ...
- 24. leetcode 409. Longest Palindrome
409. Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the le ...
- 【LeetCode】409. Longest Palindrome 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:字典统计次数 方法二:HashSet 方法三 ...
- [LeetCode] 409. Longest Palindrome 最长回文
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
- LeetCode 409 Longest Palindrome
Problem: Given a string which consists of lowercase or uppercase letters, find the length of the lon ...
随机推荐
- 转 cousera computational neuroscience week5 学习笔记(part 1)
(2013-08-14 14:58:41) 转载▼ 标签: 学习笔记 it 很久没有写博文了,之所以重新写还是因为看了coursera的computational neuroscience之后,发现这 ...
- vue2.x 父组件监听子组件事件并传回信息
利用vm.$emit 1.在父组件中引用子组件 <child @from-child-msg="listenChildMsg"></child > 2.子组 ...
- day28-python阶段性复习-基础二
六.流程控制 if条件语句 #!/usr/bin/python if 1: print 'hello python' 1表示成立,0表示不成立 条件语句排断 if : 条件 elif: 添 ...
- mysql的取整函数
一:四舍五入:ROUND() 二:向上取整:CEILING() 三:向下取整:FLOOR() 下面是示例代码. SELECT round('123.1'), round('123.4'), round ...
- 跑caffe过程中的备忘
1*1卷积比如一张500*500且厚度depth为100的图片在20个filter上做1*1卷积,那么结果大小为500*500*20 只有池化改变图片的大小 一个大的全连接层可以理解为一个神经网络,这 ...
- caffe模型参数解释
作者:wjmishuai 出处: http://blog.csdn.net/wjmishuai/article/details/50890214 原始数据是28*28 1:数据层: layer { n ...
- JDK(java se development kit)的构成
1.javac(Java compiler)编译器 通过命令行输入javac命令调用Java编译器,编译Java文件的过程中,javac会检查源程序是否符合Java的语法,没有语法 问题就会将.jav ...
- ASPNET MVC5 根 core
Asp.Net Core MVC的开源地址:https://github.com/aspnet/Mvc Asp.net MVC的开源地址:http://aspnetwebstack.codeplex. ...
- Centos7安装ansible
CentOS下部署Ansible自动化工具 1.确保机器上安装的是 Python 2.6 或者 Python 2.7 版本: python -V 2.查看yum仓库中是否存在ansible的rpm包 ...
- Python3虚拟环境安装:virtualenv、virtualenvwralpper
一:通过pip3(因python2和3共存,前文修改过pip3软连接,pip3可以安装到python3)安装virtualenv,pip3 install virtuale 二:建立虚拟环境文件目录 ...