171. Excel Sheet Column Number (Easy)

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 

思路:
1.26进制转化为十进制,ord()函数;
2.逐个读入字符串中的每个字符进行处理转换;
class Solution():
    def titleToNumber(self, s):
        """
        :type s: str
        :rtype: int
        """
        num = 0 
        for e in s:
            num = num * 26 + ord(e) - ord('A') + 1
        return num

 相关问题:http://www.cnblogs.com/yancea/p/7506456.html

posted @ 2017-09-11 12:20  Yancea  阅读(94)  评论(0编辑  收藏  举报