168. Excel Sheet Column Title

https://leetcode.com/problems/excel-sheet-column-title/description/

class Solution {
public:
    string convertToTitle(int n) {
        string res;
        while (n > 0) {
            res.push_back((n-1) % 26 + 'A');
            n = (n-1) / 26;
        }
        reverse(res.begin(), res.end());
        return res;
    }
};

 

posted @ 2018-05-15 13:42  JTechRoad  阅读(69)  评论(0编辑  收藏  举报