Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
class Solution(object):
def convertToTitle(self, n):
res = ''
t = n % 26
if t == 0:
t = 26
n -= t
res += chr(t + ord('A') - 1)
while n >= 26:
#print n
n = n / 26
t = n % 26
if t == 0:
t = 26
res += chr(t + ord('A') - 1)
if n == 26:
break
#res.reverse()
return res[::-1]
"""
:type n: int
:rtype: str
"""