Skip to content

Commit 441049d

Browse files
authored
Excel Sheet Column Number
1 parent 20b9674 commit 441049d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Dropbox/Problem#212.py renamed to Dropbox/Problem#212#719.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
Given a column number, return its alphabetical column id. For example, given 1, return "A". Given 27, return "AA".
44
"""
55
def convertToTitle(n):
6-
col = []
7-
while n:
8-
n = n-1
9-
col.append(chr((n%26)+65))
10-
n=n//26
11-
return "".join(col[::-1])
6+
column_number = 0
7+
for i in range(len(s)):
8+
column_number += ((ord(s[-1-i]) - 64) * (26**i))
9+
return column_number

0 commit comments

Comments
 (0)