Given a column title as appear in an Excel sheet, return its corresponding column number.python
For example:bash
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
...
复制代码
Example 1:app
Input: "A" Output: 1 Example 2:ui
Input: "AB" Output: 28 Example 3:spa
Input: "ZY" Output: 701code
思路:倒转s,切片*26it
代码:python3io
class Solution:
def titleToNumber(self, s: str) -> int:
revStr = s[::-1]
num=0
for i, ch in enumerate(revStr):
num = num+(ord(ch)-64)*pow(26, i)
return num
复制代码