题目:给定一个字符串,编写一个函数判定其是否为某个回文串的排列之一。回文串是指正反两个方向都一样的单词或短语。排列是指字母的重新排列。回文串不一定是字典当中的单词。
class Solution:
def canPermutePalindrome(self, s: str) -> bool:
tmp=Counter(list(s))
odd_count=0
for k,v in tmp.items():
if v%2:odd_count+=1
if odd_count>1:return False
return True
笔记:Counter函数的用法