题目描述
Given a column title as appear in an Excel sheet, return its corresponding column number.
给定在一个Excel表格中出现的列标题,求其对应的列数字。
思路一
class Solution:
def titleToNumber(self, s):
"""
:type s: str
:rtype: int
"""
sum = 0 #统计最终的结果,循环量
for c in s:
sum = sum*26 + ord(c) - 64 #现结果 = 原结果*26 + 个位数的26进制转化为十进制,但是A从1开始
return sum