Problem: 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.

Solution: Excel Sheet Column Title, Python:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# @Date : 2015-02-11 22:35:15
# @Author : NSSimacer
# @Version : 1.0
class Solution:
# @return a string
def convertToTitle(self, num):
result = ''
while num > 0:
result = chr(65 + (num - 1) % 26) + result
num = (num - 1) / 26
return result

数学题,和 Excel Sheet Column Number 很相似,反过来计算。