Posted on

Description

Submission

class Solution {
public:
    string convertToTitle(int n) {
        stringstream ss;
        for(; n != 0; n /= 26) {
            n--; // mapping from 1-26 to 0-25
            ss << char(n % 26 + 'A');
        }
        string res = ss.str();
        reverse(res.begin(), res.end());
        return res;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *