Use c array and one string construct


  • 0
    F
    class Solution {
    public:
        string convertToTitle(int n) {
            char str[10];
            int i = sizeof(str);
            while (n--) {
                str[--i] = n%26 + 'A';
                n /= 26;
            }
            return string(str+i, sizeof(str)-i);
        }
    };

Log in to reply
 

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