python leetcode 168. Excel Sheet Column Title 171. Excel Sheet Column Number
阿新 • • 發佈:2018-12-15
168. Excel Sheet Column Title
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]
171. Excel Sheet Column Number
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