0
点赞
收藏
分享

微信扫一扫

168. Excel Sheet Column Title


题目:


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的标题性质:A~Z, AA~ZZ, AAA~ZZZ, ……;Excel的标题由A-Z字符组成,本质上是26进制的表示,因此本题就是将十进制转换成26进制

代码:


class Solution {
public:
string convertToTitle(int n) {
string res = "";
while(n)
{
res = char((n-1)%26+ 'A') + res;
n = (n-1)/26;
}
return res;
}
};



举报

相关推荐

0 条评论