LeetCode刷题实战266:回文排列
Given a string, determine if a permutation of the string could form a palindrome.
示例
示例 1:
输入: “code”
输出: false
示例 2:
输入: “aab”
输出: true
示例 3:
输入: “carerac”
输出: true
解题
class Solution:
def canPermutePalindrome(self, s: str) -> bool:
dic = {}
for c in s:
if dic.get(c) == None:
dic[c] = 1
else:
dic[c] += 1
count = 0
for num in dic.values():
if num % 2 == 0:
continue
else:
count += 1
if count > 1:
return False
return True
赞 (0)