Python power of Ascii


  • 1
    R

    '''

        sum=0
        power=0
        for i in s[::-1]: # reverse the string
            sum+=((ord(i)-64)*(26**power)) 
            power+=1
        return sum   
    

    '''
    Because A is 65 in Ascii, you can find column number by subtracting 64,
    So A=1 ... Z=26. Each position moves up by a power of 26. (like hex instead of base 16 its base 26)


Log in to reply
 

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