leetcode Excel Sheet Column Title

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 

1, 一般这类涉及到随数字改变的,采用/ % 实现

package Leetcode;

public class ExcelSheetColumnTitle {
    public String convertToTitle(int n) {
    	StringBuffer result= new StringBuffer();
        while(n!=0){
        	n--;
        	result.insert(0, (char)('A'+n%26));
        	n=n/26;
        }
        return result.toString();
    }
}

  

原文地址:https://www.cnblogs.com/lilyfindjobs/p/4181532.html