Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7ba824

Browse files
authoredMay 24, 2021
Update excel-sheet-column-title.py
1 parent 613ccfc commit d7ba824

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed
 

‎Python/excel-sheet-column-title.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ def convertToTitle(self, n):
77
:type n: int
88
:rtype: str
99
"""
10-
result, dvd = "", n
11-
12-
while dvd:
13-
result += chr((dvd - 1) % 26 + ord('A'))
14-
dvd = (dvd - 1) / 26
15-
16-
return result[::-1]
17-
10+
result = []
11+
while n:
12+
result += chr((n-1)%26 + ord('A'))
13+
n = (n-1)//26
14+
result.reverse()
15+
return "".join(result)
1816

0 commit comments

Comments
 (0)
Please sign in to comment.