Leetcode 168. Excel Sheet Column Title (Easy) (cpp)

来源:互联网 发布:如何做好淘宝 编辑:程序博客网 时间:2024/06/05 11:13

Leetcode 168. Excel Sheet Column Title (Easy) (cpp)

Tag: Math

Difficulty: Easy


/*168. Excel Sheet Column Title (Easy)Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB */class Solution {public:    string convertToTitle(int n) {        string res = "";        while (n) {            res = char((n - 1) % 26 + 'A') + res;            n = (n - 1) / 26;        }        return res;    }};


0 0
原创粉丝点击