---
description: '# Easy'
---

# 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 %}

