leetcode——168——Excel Sheet Column Title

来源:互联网 发布:简繁体转换软件 编辑:程序博客网 时间:2024/05/21 11:17

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 

class Solution {public:    string convertToTitle(int n) {        string ret = "";                while(n)        {           ret =(char) ((n-1)%26 + 'A')+ret ;           n = (n-1)/26;                  }        return ret;    }};

0 0