C++ 1ms solution in 6 lines


  • 5
    P
    class Solution {
    public:
        string convertToTitle(int n) {
            string ans;
            while (n-- != 0) {
                ans = char(int('A') + n % 26) + ans;
                n /= 26;
            }
            return ans;
        }
    };
    

Log in to reply
 

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