• Excel Sheet Column Title

Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1. 1 -> A
2. 2 -> B
3. 3 -> C
4. ...
5. 26 -> Z
6. 27 -> AA
7. 28 -> AB

Solution:
1. public class Solution {
2. public String convertToTitle(int n) {
3. String res = "";
4. 5. while (n >= 1) {
6. res = (char)('A' + (n - 1) % 26) + res;
7. n = (n - 1) / 26;
8. }
9. 10. return res;
11. }
12. }