https://leetcode.com/problems/excel-sheet-column-title


Runtime: 0 ms, faster than 100.00% of C++ online submissions for Excel Sheet Column Title.
Memory Usage: 6.1 MB, less than 41.65% of C++ online submissions for Excel Sheet Column Title.



```cpp
class Solution
{
public:
  char letter;
  int left;
  vector<char> uppercase_alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

  void integer_to_letter(int num)
  {
    int index = (num - (int(num / 26) * 26)) % 26;
    index -= 1;
    if (index < 0)
    {
      index = uppercase_alphabet.size() + index;
    }
    this->letter = uppercase_alphabet[index];
    this->left = int(num / 26);
  }

  string convertToTitle(int columnNumber)
  {
    //7:34
    string output = "";

    this->left = columnNumber;

    if (this->left <= 26)
    {
      output += uppercase_alphabet[this->left - 1];
      return output;
    }

    while (true)
    {
      integer_to_letter(left);
      output = letter + output;

      if (left <= 26)
      {
        if (output[0] == 'Z')
        {
          output = uppercase_alphabet[left - 2] + output;
        }
        else
        {

          output = uppercase_alphabet[left - 1] + output;
        }
        break;
      }
    }
    if (output.find("AAZ") != string::npos) {
      return output.replace(output.find("AAZ"), 3, "ZZ");
    } else {
      return output;
    }
    //7:51
    //debug until 7:55
  }
};
```