Given a positive integer, return its corresponding column title as appear in an Excel sheet.app
For example:ui
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB ...
Example 1:rem
Input: 1 Output: "A"
Example 2:it
Input: 28 Output: "AB"
Example 3:static
Input: 701 Output: "ZY"
实现以下,这里困扰个人就是和进制的区别,好比9+1变成10,而这不是26进制,AA是27,Z是26,由于没有0的概念,因此当余数是0的时候,要特殊处理一下。di
public static String convertToTitle(int n) { StringBuilder result= new StringBuilder(); while (n > 0 ) { int merchant = n / 26; int remainder = n % 26; if(remainder==0) { result = result.append((char) ('Z')); merchant--; } else { result = result.append((char)('A'-1+remainder)); } n = merchant; } return result.reverse().toString(); }