题目
leetcode
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
依然可以看做进制转换问题(26进制)
class Solution:
# @param s, a string
# @return an integer
def titleToNumber(self, s):
if s == "":
return ""
# 形成字母表
alphabet = {}
temp = 1
for i in range(65, 91):
alphabet[chr(i)] = temp
temp += 1
rs = 0
length = len(s) - 1
for i in s:
rs += alphabet[i] * pow(26,length)
length -= 1
return rs