Created
August 5, 2015 19:22
-
-
Save viveksyngh/dc7118d8a554e903ef7a to your computer and use it in GitHub Desktop.
Given a column title as appears in an Excel sheet, return its corresponding column number.
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 titleToNumber(self, A): | |
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
num = 0 | |
for i in range(len(A)) : | |
num += (alphabet.index(A[i]) + 1) * (26 ** (len(A) - i - 1) ) | |
return num | |
#A -> 1 | |
#B -> 2 | |
#C -> 3 | |
#... | |
#Z -> 26 | |
#AA -> 27 | |
#AB -> 28 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment