> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Excel Sheet Column Number Python Solution

> Tested Python solution for LeetCode 171 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 171, [Easy](/catalog/easy). Topics: [Math](/catalog/topics/math), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/excel-sheet-column-number/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 171   # by problem number
lcpy gen -s excel_sheet_column_number   # by problem name
```

## Problem

Given a string `columnTitle` that represents the column title as appears in an Excel sheet, return *its corresponding column number*.

For example:

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

### Examples

```
Input: columnTitle = "A"
Output: 1
```

```
Input: columnTitle = "AB"
Output: 28
```

```
Input: columnTitle = "ZY"
Output: 701
```

### Constraints

* 1 \<= columnTitle.length \<= 7
* columnTitle consists only of uppercase English letters.
* columnTitle is in the range \["A", "FXSHRXW"].

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/excel_sheet_column_number/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/excel_sheet_column_number/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def title_to_number(self, column_title: str) -> int:
        result = 0
        for char in column_title:
            result = result * 26 + (ord(char) - ord("A") + 1)
        return result
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.