# 171. Excel Sheet Column Number

{% hint style="info" %}
Key idea: 26^n
{% endhint %}

```python
class Solution:
    def titleToNumber(self, s: str) -> int:
        res = 0
        i = 1
        for cha in reversed(s):
            res += i*(ord(cha)-64)
            i *= 26
        return res
```

{% hint style="success" %}
ord() 函数是python内置函数，将char转换成int，比如ord(‘A')=65, ord('a')=97.

两个char类型在python里是无法直接加减运算的，必须转换成数字才行。
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://r24zeng.gitbook.io/leetcode-notebook/bu-chong-4060-dao/171.-excel-sheet-column-number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
