Given a positive integer, return its corresponding column title as appear in an Excel sheet.python
For example:bash
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
...
複製代碼
Example 1:app
Input: 1 Output: "A" Example 2:ui
Input: 28 Output: "AB" Example 3:spa
Input: 701 Output: "ZY"code
代碼:python3string
class Solution:
def convertToTitle(self, n: int) -> str:
str = ''
while n > 0 :
if (n%26) == 0:
str = str+""
else:
str = str+chr(64+n%26)
n = int(n/26)
return str
複製代碼