릿코드(LEETCODE)

168. Excel Sheet Column Title

cepiloth 2020. 2. 6. 16:14
반응형

 

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

 

Excel Sheet Column Title - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

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

 

반응형