输入: s = "carerac"
输出: True
解释:
"carerac" --> "carerac"
输入测试数据 (每行一个参数)如何理解测试数据?
class Solution:
"""
@param s: the given string
@return: if a permutation of the string could form a palindrome
"""
'''
大致思路:
1.初始化c = 0,如果存在当前字符计数模除2不为0的超过一次情况的话,则返回Fasle,否则True
'''
def canPermutePalindrome(self,s):
c = 0
dic = {}
for i in s:
dic[i] = dic.get(i,0) + 1for k,v in dic.items():
if v % 2 != 0:
c += 1if c > 1:
return False
return True