题解 | Excel 表列序号
Excel 表列序号
https://www.nowcoder.com/practice/700738eaa67342ba8f92c13cbbb7b29d
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param S string字符串
# @return int整型
#
class Solution:
def getNumber(self, S: str) -> int:
# write code here
'''alp, ans, S = "abcdefghijklmnopqrstuvwxyz", 0, S[::-1]
for i in range(len(S)):
ans += (alp.index(S[i])+1)*26**i'''
alp, ans = "abcdefghijklmnopqrstuvwxyz", 0
for c in S:
ans = ans*26+alp.index(c)+1
return ans
#类似26进制转化为10进制
查看1道真题和解析
安克创新 Anker公司福利 814人发布