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
思路:本题就是一个普通的进位问题,逢26进一位。
代码如下(已通过leetcode)
public class Solution {
public String convertToTitle(int n) {
String ans="";
String temp;
boolean isfirst=true;
while(n>0) {
int dig1=(n-1)%26;
temp=(char)(dig1+'A')+"";
ans=temp+ans;
n=(n-1)/26;
}
return ans;
}
}