Palindrome Permutation

Given a string, determine if a permutation of the string could form a palindrome.

For example, "code" -> False, "aab" -> True, "carerac" -> True.


    def canPermutePalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        dict = {}
        for i in range(len(s)):
            if s[i] in dict:
                if dict[s[i]] == 0:
                    dict[s[i]] = 1
                else:
                    dict[s[i]] -= 1
            else:
                dict[s[i]] = 1
        return sum(dict.values()) == 1 or sum(dict.values()) == 0

results matching ""

    No results matching ""