clueless coding // TODO: be smarter

LeetCode Excel Sheet Column Title: CPP Solution



TL;DR Code Solution


string convertToTitle(int n) {

    string result = "";

    while (n) {
        char letter = (n - 1) % 26 + 'A';
        result = letter + result;
        n = (n - 1) / 26;
    }

    return result;

}