Leetcode 171 Excel Sheet Column Number

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进制下ASCII码的转换

class Solution:
    # @param {string} s
    # @return {integer}
    def titleToNumber(self, s):
        sum = 0
        for x in s:
            sum = 26*sum + ord(x) - ord('A') + 1
        return sum

 

posted @ 2015-07-08 21:46  lilixu  阅读(128)  评论(0编辑  收藏  举报