171. Excel Sheet Column Number

# Easy

Key idea: 26^n

class Solution:
    def titleToNumber(self, s: str) -> int:
        res = 0
        i = 1
        for cha in reversed(s):
            res += i*(ord(cha)-64)
            i *= 26
        return res

Last updated

Was this helpful?