Leetcode_Excel Sheet Column Number

Excel Sheet Column Number

Given a column title as appear in an Excel sheet, return its corresponding column number.
(将EXCEL表格中的列名称转换成数值)

Example:



1. 进制转换

这道题可以看做是一道进制转换的题目,将26进制转换成十进制。具体实现方法如下:

1
2
3
4
5
6
7
8
9
class Solution:
def titleToNumber(self, s: str) -> int:
num = 0

for char in s:
num = num * 26
num += ord(char) - ord('A') + 1

return num