168. Excel Sheet Column Title

原题链接:https://leetcode.com/problems/excel-sheet-column-title/description/
这道题目虽然是easy级别的,初看也以为很简单,但是我并未能写出一个完整的实现来。最后,还是抄袭别人的答案:

/**
 * Created by clearbug on 2018/2/26.
 */
public class Solution {

    public static void main(String[] args) {
        Solution s = new Solution();
        for (int i = 26; i < 55; i++) {
            System.out.println(s.convertToTitle(i));
        }
    }

    public String convertToTitle(int n) {
        StringBuilder sb = new StringBuilder();
        while (n > 0) {
            n--;
            sb.append(convertToTitleHelper(n % 26));
            n /= 26;
        }
        return sb.reverse().toString();
    }

    private char convertToTitleHelper(int n) {
        return (char) ('A' + n);
    }
}
原文地址:https://www.cnblogs.com/optor/p/8618770.html