Excel Sheet Column Title(math)
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
...Input:
1
Output:
"A"Input:
28
Output:
"AB"Last updated
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
...Input:
1
Output:
"A"Input:
28
Output:
"AB"Last updated
Input:
701
Output:
"ZY"class Solution(object):
def convertToTitle(self, n):
"""
:type n: int
:rtype: str
"""
s = ''
while n>0:
rem = (n-1)%26
s=chr(ord('A')+rem)+s #想象 A+25 =Z 所以要n-1
n=(n-1)/26
return sclass Solution(object):
def convertToTitle(self, n):
"""
:type n: int
:rtype: str
"""
return "" if n==0 else self.convertToTitle((n-1)/26)+chr((n-1)%26+ord('A'))