88ms solution in Python


  • 0
    class Solution(object):
        def mapToInt(self, ch):
            return 1 + ord(ch) - ord('A')
        
        def titleToNumber(self, s):
            length = len(s)
            base = length - 1
            
            sum = 0
            for ch in s:
                sum += (26 ** base) * self.mapToInt(ch)
                base -= 1
            return sum

Log in to reply
 

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