Given a string, find out if its characters can be rearranged to form a palindrome.

Example

For inputString = "aabb", the output should be
palindromeRearranging(inputString) = true.

We can rearrange "aabb" to make "abba", which is a palindrome.

我的解答:

 def palindromeRearranging(inputString):
for s in inputString:
if inputString.count(s) % 2 == 0:
inputString = inputString.replace(s,'')
if len(inputString) == 0 or len(inputString) == 1:
return True
elif len(inputString) % 2 == 1:
return inputString.count(inputString[0]) == len(inputString)
else:
return False

膜拜大佬:

def palindromeRearranging(inputString):
return sum([inputString.count(i)%2 for i in set(inputString)]) <= 1

Code Signal_练习题_palindromeRearranging的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  9. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

随机推荐

  1. ps与grep组合命令使用

    管道命令 我们在做运维的时候,经常会使用这个命令ps -ef | grep nginx. ps -ef 表示显示所有进程的消息. | 是管道命令.通常需要借助管道命令”|”多个命令的组合,形式如下: ...

  2. Linux中的任务调度

    1.crond,linux中的任务调度器 crond的概念和crontab是不可分割的.crontab是一个命令,常见于Unix和类Unix的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入 ...

  3. Python中的匿名函数lambda的用法

    一.lambda函数的简介  对lambda函数,它其实是一个类似于def的函数,只不过lambda是一个不需要定义函数名的匿名函数.当我们在有些时候,需要做一些简单的数学计算时,如果定义一个def函 ...

  4. 常用的PHP超全局变量$_SERVER 收集整理

    传送带:https://www.cnblogs.com/rendd/p/6182918.html

  5. 第三方库PIL

    第三方库PIL 一.Python简介 Python是一门简洁高效.通俗易懂的高阶动态编程语言,也可以理解成是一种面向对象的解释型计算机程序设计语言. Python具有丰富和强大的库.也经常被行内人员称 ...

  6. Eigenface与PCA人脸识别算法实验

    简单的特征脸识别实验 实现特征脸的过程其实就是主成分分析(Principal Component Analysis,PCA)的一个过程.关于PCA的原理问题,它是一种数学降维的方法.是为了简化问题.在 ...

  7. 南昌网络赛 I. Max answer (单调栈 + 线段树)

    https://nanti.jisuanke.com/t/38228 题意给你一个序列,对于每个连续子区间,有一个价值,等与这个区间和×区间最小值,求所有子区间的最大价值是多少. 分析:我们先用单调栈 ...

  8. C#以管理员权限运行源码,C#软件获取管理员权限,c#获取管理员权限

    C#以管理员权限运行源码,C#软件获取管理员权限,c#获取管理员权限 发布时间:2014-10-19 21:40内容来源:未知 点击: 次 windows 7和vista提高的系统的安全性,同时需要明 ...

  9. C# openfiledialog的使用

    文件对话框(FileDialog) 一.打开文件对话框(OpenFileDialog) 1. OpenFileDialog控件有以下基本属性 InitialDirectory 对话框的初始目录Filt ...

  10. asp.net 网站在Apache下的配置,就这么简单

    asp.net 网站在Apache下的配置,就这么简单 # # Virtual Hosts # # If you want to maintain multiple domains/hostnames ...