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 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
上一篇:js/jq基础(日常整理记录)-3-一个自定义表格


下一篇:vue实现自定义表格列