给定一个正整数, 返回它在 Excel 表中相对应的列名称.
示例:
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
详见: https://leetcode.com/problems/excel-sheet-column-title/description/
- class Solution {
- public:
- string convertToTitle(int n) {
- string res="";
- while(n)
- {
- res=char((n-1)%26+'A')+res;
- n=(n-1)/26;
- }
- return res;
- }
- };
参考: https://www.cnblogs.com/ganganloveu/p/4175848.html
来源: http://www.bubuko.com/infodetail-2552625.html