Simple C++ Solution through Base-26 Number Conversion


  • 0
    M
    class Solution {
    public:
        string convertToTitle(int n) {
            string result;
            while (n) {
                result.insert(0, 1, 'A' + (--n % 26));
                n /= 26;
            }
            return result;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.