问题描述:
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思路: 10进制转为26进制,但不是从0开始,因此每次都要-1
<span style="font-size:18px;">public class Solution {
public String convertToTitle(int n) {
String re = "";
while(n>0){
re = (char)((n-1)%26+'A') + re;
n = (n-1)/26;
}
return re;
}
}</span>