Simple and sweet and short soln


#1

string Solution::convertToTitle(int n)
{
string str="";
while(n!=0)
{
if(n>=1 && n<=26)
{
str += n+65-1;
break;
}

    int a = n%26;
    if(a == 0)
    {
        n = n/26-1;
        str += 'Z';
    }
    else
    {
        n = n/26;
        str += a+65-1;
    }
}
reverse(str.begin(),str.end());
return str;

}