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.
Subscribe to see which companies asked this question
Solution: And Excel Sheet Column number Instead, this time is 10 binary to 26 binary. From the low to high, each into a, then the original number is reduced by 26 times times, and then 26, then subtract the remainder, then reduce 26 times times, and so on, you can find the letters in each position. Finally, just flip the whole string over a bit.
classSolution { Public: stringConverttotitle (intN) {stringres =""; while(N >0) { intrem = n% -; if(REM = =0) {res+="Z"; N-= -; } Else{res+= (Char) (REM-1+'A'); N-=REM; } N/= -; } reverse (Res.begin (), Res.end ()); returnRes; }};
[Leetcode]62. Excel Sheet column Title Excel columns ordinal