1.题目描述
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
26进制转10进制
2.题目分析
从字符串末尾开始遍历,依次加数
3.解题思路
1 class Solution(object): 2 def titleToNumber(self, s): 3 """ 4 :type s: str 5 :rtype: int 6 """ 7 l=len(s) 8 i=l-1 9 temp=ord(‘A‘)-1 10 n=0 11 while i>=0: 12 n+=26**(l-i-1)*(ord(s[i])-temp) 13 i-=1 14 return n 15