168 Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
Brain storm:
I first opened excel to try and simulate the pattern for myself. I first noticed that num % 26 always returns the least significant letter. Then it hit me, this is just base 26, with [1-26] represented through [A-Z]. So all I had to do was convert the given number into base 26 using this format.
Base conversion algorithm works as follows:
The most significant 'digit' is the number of time the max power can fit into the original number. We mod by 26 because we want to get the mapping letter.
The next significant 'digit' is the same thing with the max power shifted down by 1.
Last updated