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;
	}

猜你喜欢

转载自blog.csdn.net/u011243684/article/details/84843773