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
浙公网安备 33010602011771号