Instead of 1 -> A, 26 -> Z, we can assume that 0 -> A, 25 -> Z, and then here comes the base 26 representation, it's similar when you convert a number from base 10 to base 2

```
public class Solution {
public String convertToTitle(int n) {
String res = "";
while(n != 0) {
char ch = (char)((n - 1) % 26 + 65);
n = (n - 1) / 26;
res = ch + res;
}
return res;
}
}
```