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
解题思路:
JAVA实现如下:
static public String convertToTitle(int n) { StringBuilder sb = new StringBuilder(); while (n > 0) { int temp=‘A‘+n%26-1; if(temp<‘A‘) temp+=26; sb.insert(0,(char)temp); n/=26; if(temp==‘Z‘) n--; } return sb.toString(); }
时间: 2024-12-27 03:30:54