math
strings
Spreadsheet columns are labelled A, B, ..., Z, AA, AB, .... Given a column title as a string of uppercase letters, return its corresponding 1-based column number.
So A -> 1, B -> 2, Z -> 26, AA -> 27, AB -> 28, and so on.
Input / output
- Input:
columnTitle: stringof uppercase lettersA–Z - Output: the column number as an integer
Examples
columnTitle = "A"returns1.columnTitle = "AB"returns28.columnTitle = "ZY"returns701.
Constraints
1 <= columnTitle.length <= 7columnTitlecontains only uppercase English letters.- The value is in the range
[1, 2^31 - 1].
Follow-up
This is base-26 with digits 1..26 (there is no zero digit). Why does the absence of a zero digit make it bijective base-26 rather than ordinary base-26?
Examples
Example 1
Input: columnTitle = "A"
Output: 1
Example 2
Input: columnTitle = "AB"
Output: 28
Example 3
Input: columnTitle = "ZY"
Output: 701
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.