key: here A to Z represent to 1 - 26 , so preform n - 1 in each loop to change it to 0 - 25
Runtime: 0 ms / beats 11.37%
Reference:discuss
class Solution {
public:
string convertToTitle(int n) {
char c[28] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string res = "\0";
while(n > 0)
{
res = c[(n - 1) % 26] + res;
n = (n - 1) / 26;
}
return res;
}
};