题目来源
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
这个题目呢,一看呢,就感觉比较简单,感觉就是一个10进制转26进制的问题。代码如下:
class Solution {
public:
string convertToTitle(int n) {
string r;
while (n != 0) {
int x = (n-1) % 26;
r += char(x+65);
n = (n - 1) / 26;
}
reverse(r.begin(), r.end());
return r;
}
};