Palindrome Permutation
Description:
Given a string, determine if a permutation of the string could form a palindrome.
Example
Given s = “code”, return False.
Given s = “aab”, return True.
Given s = “carerac”, return True.
Code:
class Solution:
"""
@param s: the given string
@return: if a permutation of the string could form a palindrome
"""
def canPermutePalindrome(self, s):
# write your code here
dic = {}
for i in range(len(s)):
dic[s[i]] = dic[s[i]]+1 if s[i] in dic else 1
numOfOne = 0
for i in dic:
if dic[i]%2 == 1:
numOfOne += 1
if numOfOne > 1:
return False
return True