1. 程式人生 > >168. Excel Sheet Column Title

168. Excel Sheet Column Title

exce 返回 osi div column tle while ger excel

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 
題目含義:給定一個int數,返回其代表的字符串,規則如上
1     public String convertToTitle(int n) {
2          String result = "";
3 while (n > 0) { 4 result = (char) (‘A‘ + (n - 1) % 26) + result; 5 n = (n - 1) / 26; 6 } 7 return result; 8 }



168. Excel Sheet Column Title