168. Excel Sheet Column Title

 

 

168. Excel Sheet Column Title

 code

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

 

 

 

https://leetcode.com/problems/excel-sheet-column-title/description/

posted on 2018-12-07 09:35  鹅要长大  阅读(148)  评论(0)    收藏  举报

导航