标签:appear solution its class on() for col ber 字符串
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
171. Excel Sheet Column Number (Easy)
标签:appear solution its class on() for col ber 字符串
原文地址:http://www.cnblogs.com/yancea/p/7504381.html