C++ solution easy to understand


  • -2
    C

    string convertToTitle(int n) {
    string ss, rss;
    int off;
    while (n>0){
    off=n%26;
    off=(off==0)?26:off;
    ss+=(off-1+'A');
    n=(n-off)/26;
    }
    for (int i=ss.length()-1; i>=0;i--)
    rss+=ss[i];
    return rss;
    }


Log in to reply
 

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