168. Excel Sheet Column Title

来源:互联网 发布:js给时间控件赋值 编辑:程序博客网 时间:2024/06/05 11:07

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

    1 -> A    2 -> B    3 -> C    ...    26 -> Z    27 -> AA    28 -> AB 

Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.

class Solution 

{
public:
    string convertToTitle(int n)

     {

          string result="";

         if(n<=0)

          return result;

        while(n>0)

         {

              n--;

             result.insert(0,1,n%26+'A');

             n=n/26;

         }

         return result;

     }
};

原创粉丝点击