Last active
August 29, 2015 14:26
-
-
Save viveksyngh/470dad367a7e3c119649 to your computer and use it in GitHub Desktop.
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convertToTitle(A): | |
aplhabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
column = "" | |
while A > 0 : | |
temp = A%26 | |
#print temp, A | |
if temp == 0 : | |
temp = 26 | |
A = A - 1 | |
#print aplhabet[temp-1] | |
column = aplhabet[temp-1] + column | |
A = A/26 | |
return column | |
#1 -> A | |
#2 -> B | |
#3 -> C | |
#... | |
#26 -> Z | |
#27 -> AA | |
#28 -> AB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment