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
給定一個非正整數,返回他對應的Excel列標題。app
題目本質就是將10進制數轉換成26進制數,使用A-Z字母表示。spa
算法實現類.net
public class Solution { public String convertToTitle(int n) { char[] result = new char[20]; int index = 20; n--; do { result[--index] = (char) ('A' + n % 26); n = n / 26 - 1; } while (n >= 0); return new String(result, index, 20 - index); } }