Simple C++ solution using n-1


  • 0
    F
    string convertToTitle(int n) {
        string s;
        while(n != 0) s = char('A'  + (n-1)%26) + s, n = (n-1) / 26;
        
        return s;
    }

Log in to reply
 

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