Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1, A 2, B 3, C ... AA, Z
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
This problem and Excel Sheet column number is the Excel table ordinal is together, but I spend more time on this topic than above, the starting principle is the same, is a request, the problem from the low to high, each into a, then the original number is reduced by 26 times times, After 26, subtract the remainder, then reduce it by 26 times times, and so on, you can find the letters in each position. Finally, just flip the whole string over a bit. The code is as follows:
classSolution { Public: stringConverttotitle (intN) {stringres =""; while(n) {if(n% -==0) {res+='Z'; N-= -; } Else{res+ = n% --1+'A'; N-= n% -; } N/= -; } reverse (Res.begin (), Res.end ()); returnRes; }};
[Leetcode] Excel Sheet column title find Excel table columns name