Skip to content

Instantly share code, notes, and snippets.

@viveksyngh
Last active August 29, 2015 14:26
Show Gist options
  • Save viveksyngh/470dad367a7e3c119649 to your computer and use it in GitHub Desktop.
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.
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