class Solution: # @param s, a string # @return an integer def titleToNumber(self, s): ret = 0 i = 0 while len(s) != 0 : tmp = s[len(s) - 1] ret += ord(tmp) - ord('A') + 1 + pow (26, i) s = s[:len(s) - 1] i += 1 return ret
Every time I run this code, it shows:
But, it is almost impossible that my code will output 28 for "AA".
I have tried this code a thousand time in my local machine and its output is 27.
I have no idea, this is really wired.