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

leetcode Excel Sheet Column Title

Excel Sheet Column Title 題目:https://leetcode.com/problems/excel-sheet-column-title/

把數字轉化為Excel 的列====本質等於把10進位制的數轉化為26進位制的字串

 

public static void main(String[] args) {
		int n=26;
		String s = convertToTitle(n);
		System.out.println(s);
	}
	public static  String convertToTitle(int n) {
		String str="";
		while(n>0){
			int num=(n-1)%26;
			str=(char)('A'+num)+str;
			n=(n-1)/26;
		}
		return str;
	}