Skip to content
LC-0171 Easy LeetCode

171. Excel Sheet Column Number

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 66% Topics: Math, String
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def titleToNumber(self, s):
        """
        :type s: str
        :rtype: int
        """
        result = 0
        for i in xrange(len(s)):
            result *= 26
            result += ord(s[i]) - ord('A') + 1
        return result


Solution from kamyu104/LeetCode-Solutions · MIT