My 0ms C++ Solution


  • 0
    S
    class Solution {
    public:
        string convertToTitle(int n) {
            stack<int> digits;
            int tmp = n;
            while(tmp>0){
                tmp -= 1;
                if(tmp == 0){
                    digits.push(0);
                    continue;
                }
            
                int digit = tmp %26;
                digits.push(digit);
                tmp -= digit;
                tmp /= 26;
            }
            stringstream sstm;
            while(digits.empty()!=true)
            {
                sstm<<string(1,'A'+digits.top());
                digits.pop();
            }
            return sstm.str();
        }
    };

Log in to reply
 

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