题目:
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
题意:
给定一个正整数,返回其在EXCEL表格中所对应的列;
思路:
事实上就是将一个十进制的数转换为26进制的数,由于下标是从1开始的,所以要减1操作
代码:0ms
class Solution { public: string convertToTitle(int n) { string ret = ""; while(n){ ret = (char)((n-1)%26 + 'A') + ret; n = (n-1)/26; } return ret; } };