"Un livre pour former des compétences en programmation pour combattre dans le monde" Exemple de réponse au code Python --1.4 Séquence de phrases
def isPermutationOfPalindrome(phrase):
    phrase = phrase.lower()
    table = buildCharFrequencyTable(phrase)
    return checkMaxOneOdd(table)
def checkMaxOneOdd(table):
    
    foundOdd = False
    for count in range(len(table)):
        if table[count]%2 == 1:
            if foundOdd:
                return False
            foundOdd = True
    return True 
def getCharNumber(c):
    a = ord("a")
    z = ord("z")
    val = ord(c)
    if a <= val and val <= z:
        return val - a
    
    return -1
def buildCharFrequencyTable(phrase):
    
    table = [0] * 26
    for id in range(len(phrase)):
        c = phrase[id]
        x = getCharNumber(c)
        if x != -1 :
            table[x] = table[x] + 1
    
    return table
print(isPermutationOfPalindrome("Tact Coa"))
        Recommended Posts