本文共 629 字,大约阅读时间需要 2 分钟。
class Solution: def convertToTitle(self, n): """ :type n: int :rtype: str """ s='' while n>26: yu=n%26 if yu==0: n=n//26-1 s+='Z' else: n=n//26 s+=chr(64+yu) s+=chr(64+n) return s[::-1]
class Solution: def titleToNumber(self, s): """ :type s: str :rtype: int """ n=len(s) res=0 for i in range(n-1,-1,-1): res+=(ord(s[n-1-i])-64)*26**i return res
转载地址:http://ywahj.baihongyu.com/