Leetcode 171 Excel Sheet Column Number python

题目:

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进制
1 class Solution(object):
2     def titleToNumber(self, s):
3         length = len(s)
4         if length == 0: return 0
5         ans = 0
6         for i in range(length):
7             ans = ans * 26 + ord(s[i]) - ord('A') + 1
8         return ans

 

posted on 2016-04-20 12:18  def_sysu  阅读(194)  评论(0)    收藏  举报

导航