Palindrome Permutation

Problem: Palindrome Permutation

We just calculate frequency of each letter and if there are two odd numbers it can't be palindrome.

Code in Python:

from collections import defaultdict

class Solution(object):
    def canPermutePalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        odd = True if len(s) % 2 == 1 else False
        dict = defaultdict(int)
        for c in s:
            dict[c] += 1
        for x in dict.values():
            if x and odd and x % 2 == 1: odd = False
            elif x and x % 2 == 1: return False
        return True

results matching ""

    No results matching ""