My clean C++ solution


  • 0
    class Solution {
    public:
        string convertToTitle(int n) {
            string res;
            char c;
            while(n){
                c = 'A' + (n - 1) % 26;
                res = c + res;
                n = (n - 1) / 26;
            }
            return res;
        }
    };
    

Log in to reply
 

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