Skip to content

Commit d7a34e3

Browse files
authored
Update excel-sheet-column-title.py
1 parent 5c7503a commit d7a34e3

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Python/excel-sheet-column-title.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Time: O(logn)
22
# Space: O(1)
3-
#
3+
44
# Given a positive integer, return its corresponding column title as appear in an Excel sheet.
55
#
66
# For example:
@@ -12,19 +12,22 @@
1212
# 26 -> Z
1313
# 27 -> AA
1414
# 28 -> AB
15-
#
1615

17-
class Solution:
18-
# @return a string
19-
def convertToTitle(self, num):
16+
class Solution(object):
17+
def convertToTitle(self, n):
18+
"""
19+
:type n: int
20+
:rtype: str
21+
"""
2022
result, dvd = "", num
2123

2224
while dvd:
2325
result += chr((dvd - 1) % 26 + ord('A'))
2426
dvd = (dvd - 1) / 26
2527

2628
return result[::-1]
27-
29+
30+
2831
if __name__ == "__main__":
2932
for i in xrange(1, 29):
30-
print Solution().convertToTitle(i)
33+
print Solution().convertToTitle(i)

0 commit comments

Comments
 (0)