3 line Python solution using cancellation technique

  • 0
    class Solution(object):
        def canPermutePalindrome(self, s):
            chars = set()
            for char in s:
                chars.remove(char) if char in chars else chars.add(char)
            return not chars if len(s) % 2 == 0 else len(chars) == 1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.