168. Excel Sheet Column Title
- Total Accepted: 92486
- Total Submissions: 371421
- Difficulty: Easy
- Contributors: Admin
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
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
Subscribe to see which companies asked this question.
public class demo1 {
public String convertToTitle(int n){
String result="";
if(n>0)
result=convertToTitle(--n/26)+(char)('A' + n % 26);
return result;
}
public static void main(String[] args){
int n=52;
demo1 r = new demo1();
System.out.println(r.convertToTitle(n));
}
}