LeetCode#168 Excel Sheet Column Title

来源:互联网 发布:简约个人业务源码 编辑:程序博客网 时间:2024/05/23 13:10

key: here A to Z represent to 1 - 26 , so preform n - 1 in each loop to change it to 0 - 25
Runtime: 0 ms / beats 11.37%
Reference:discuss

class Solution {public:    string convertToTitle(int n) {        char c[28] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";        string res = "\0";        while(n > 0)        {            res = c[(n - 1) % 26] + res;            n = (n - 1) / 26;        }        return res;    }};
0 0
原创粉丝点击