/171. Excel Sheet Column Number

171. Excel Sheet Column Number

Easy
Probability67.4% acceptance

Given a string identifier consisting of uppercase English letters, interpret it as a base-26 number where A corresponds to 1, B to 2, ..., Z to 26. Compute and return its integer value.

Example 1

Input: "BAA"

Output: 1053

Explanation: B=2, A=1, A=1; 2*26^2 + 1*26^1 + 1*26^0 = 2*676 + 1*26 + 1*1 = 1352 + 26 + 1 = 1379

Example 2

Input: "ZZ"

Output: 702

Explanation: Z=26, Z=26; 26*26^1 + 26*26^0 = 676 + 26 = 702

Example 3

Input: "C"

Output: 3

Explanation: C=3; 3*26^0 = 3

Constraints

  • 1 <= len(identifier) <= 7
  • identifier consists only of uppercase English letters (A-Z)
  • identifier is in the range ["A", "FXSHRXW"]
Python (current runtime)

Case 1

Input: "AAA"

Expected: 703

Case 2

Input: "AZ"

Expected: 52

Case 3

Input: "X"

Expected: 24

Case 4

Input: "BCD"

Expected: 1431

Case 5

Input: "ZZZ"

Expected: 18278