Skip to content

Files

Latest commit

Jul 23, 2023
e1b8af0 · Jul 23, 2023

History

History

0171-Excel Sheet Column Number

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
No commit message
Jul 23, 2023
No commit message
Jul 23, 2023
No commit message
Jul 23, 2023

171. Excel Sheet Column Number

Given a column title as appear in an Excel sheet, return its corresponding column number.

For example:

    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28
    ...

Example 1:

Input: "A"
Output: 1

Example 2:

Input: "AB"
Output: 28

Example 3:

Input: "ZY"
Output: 701

Solutions (Python)

1. Solution

class Solution:
    def titleToNumber(self, s: str) -> int:
        ret = 0
        for c in s:
            ret *= 26
            ret += ord(c) - 64
        return ret