-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0171.py
More file actions
45 lines (37 loc) · 925 Bytes
/
0171.py
File metadata and controls
45 lines (37 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 171. Excel表列序号
# 给定一个Excel表格中的列名称,返回其相应的列序号。
# 例如,
# A -> 1
# B -> 2
# C -> 3
# ...
# Z -> 26
# AA -> 27
# AB -> 28
# ...
# 示例 1:
# 输入: "A"
# 输出: 1
# 示例 2:
# 输入: "AB"
# 输出: 28
# 示例 3:
# 输入: "ZY"
# 输出: 701
# 来源:力扣(LeetCode)
# 链接:https://leetcode-cn.com/problems/excel-sheet-column-number
# 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution:
ASICII_A = 65
notation = 26
def titleToNumber(self, s: str) -> int:
retVal = 0
length = len(s)
for i in range(0, length):
char = s[length-1-i]
num = ord(char)-self.ASICII_A+1
num = num * pow(26, i)
retVal += num
return retVal
s = Solution()
o = s.titleToNumber("AB")