Code Signal_练习题_palindromeRearranging
Given a string, find out if its characters can be rearranged to form a palindrome.
Example
For inputString = "aabb"
, the output should bepalindromeRearranging(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的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- 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) + ...
随机推荐
- Rabbitmq 消息对列 生产者与消费者的具体实现 springboot
RabbitMQ 基本介绍 RabbitMQ的设计理念是.只要有接收消息的队列. 邮件就会存放到队列里. 直到订阅人取走. . 如果没有可以接收这个消息的消息队列. 默认是抛弃这个消息的.. 我实现的 ...
- mysql的left join、 right join和inner join
1.定义 left join:左联接,返回包括左表中的所有记录和右表中符合条件的记录. right join:右联接,返回包括右表中的所有记录和左表中符合条件的记录. inner join:等值联接, ...
- 1.需要对txt存放的测试数据做去重处理,代码如下
采用集合去重,在新文件里逐行写入,达成目的 old_file = "D:/testdata/memberId.txt" #old result_file = "D:/te ...
- TX2 i2c-tools使用
安装: apt-get install libi2c-dev i2c-tools 检测i2c总线数目 用i2cdetect检测有几组i2c总线在系统上: i2cdetect -l 可以看到系统中有9组 ...
- ThreadLocal系列(三)-TransmittableThreadLocal的使用及原理解析
ThreadLocal系列(三)-TransmittableThreadLocal的使用及原理解析 上一篇:ThreadLocal系列(二)-InheritableThreadLocal的使用及原理解 ...
- 一段关于Unix、Linux和Windows的暗黑史
"SCO在言语上变得越来越好斗,而且还拒绝展示有关诉讼的任何证据,一切都似乎在表明,SCO只不过是在那里拉虎皮做大旗地狂言乱语.但是,微软 决不会轻易放弃这么可以一个利用这些狂言乱语的好机会 ...
- DB2 close auto commit
db2 关闭命令行CLP自动提交 --临时关闭自动提交 #db2 "update command options using C off --永久关闭自动提交 ----linux 环境下 # ...
- android逆向基础:apk 反编译 重打包 重签名
apk 反编译大家都比较熟悉,这里只做一个笔记. 1 反编译 apk apktool d perfect.apk 这样就把资源文件解压缩了, classes.dex 也反编译成了 smali 文件 2 ...
- 部署herko小记
1 先执行如下 heroku run rake db:migrate
- memcached 学习笔记 2
原理 1 核心组件 Memcached有两个核心组件组成:服务端(ms)和客户端(mc). 首先mc拿到ms列表,并对key做hash转化,根据hash值确定kv对所存的ms位置. 然后在一个memc ...