Use table and toggle int values to speed up


  • 0
    C

    We only need to toggle 1 and 0 to indicate odd or even in a 256 long list.

    class Solution(object):
    def canPermutePalindrome(self, s):
    
        letterCounts=[0]*256
        for c in s:
            ic=ord(c)
            letterCounts[ic]=0 if letterCounts[ic] else 1
        return sum(letterCounts)<=1

Log in to reply
 

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