Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 402 Bytes

168.md

File metadata and controls

18 lines (16 loc) · 402 Bytes

168. Excel Sheet Column Title

Solution 1 (time O(1), space O(1))

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