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
时间: 2024-10-12 16:40:30