LeetCode *** 168. Excel Sheet Column Title

来源:互联网 发布:minecraft 源码 unity 编辑:程序博客网 时间:2024/05/17 01:26

题目:

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 s="",t="";                while(n){            n=n-1;            s+='A'+n%26;            n/=26;        }                int len=s.length();                for(int i=len-1;i>=0;--i){            t+=s[i];        }                return t;    }};

0 0
原创粉丝点击