LC 0168 [E] Excel Sheet Column Title - ALawliet/algorithms GitHub Wiki

class Solution:
    def convertToTitle(self, num):
        alphabet = list(string.ascii_uppercase)
        res = deque()
        while num != 0:
            q, r = divmod(num-1, 26) # n-1 for 0-25
            res.appendleft(alphabet[r])
            num = q
        return ''.join(res)