Excel Sheet Column Title
Given a non-zero 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
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
Excel序是这样的:A~Z, AA~ZZ, AAA~ZZZ, ……
本质上就是将一个10进制数转换为一个26进制的数
class Solution { public: string convertToTitle(int n) { if(n < 1) return ""; else { string result = ""; while(n) {//get every letter in n from right to left n --; char c = n%26 + ‘A‘; result += c; n /= 26; } reverse(result.begin(), result.end()); return result; } } };
【LeetCode】Excel Sheet Column Title
原文:http://www.cnblogs.com/ganganloveu/p/4175848.html