python:
class Solution:
def convertToTitle(self, n):
"""
:type n: int
:rtype: str
"""
ans = ''
while n > 0:
n = n - 1
j = n%26
ans = "{}{}".format(chr(j+65), ans)
n = n//26
return ans
c++:
class Solution {
public:
string convertToTitle(int n) {
return n==0? "":convertToTitle(n/26) + (char)(--n%26 + 'A');
}
};