Last active
July 18, 2021 13:30
-
-
Save hungneox/8fcff676c2b9b8d02fdb641bc07b44ee to your computer and use it in GitHub Desktop.
Excel Sheet Column Title
This file contains hidden or 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
# https://leetcode.com/problems/excel-sheet-column-title | |
class Solution: | |
def convertToTitle(self, columnNumber: int) -> str: | |
""" | |
Success | |
Details | |
Runtime: 28 ms, faster than 77.90% of Python3 online submissions for Excel Sheet Column Title. | |
Memory Usage: 14.1 MB, less than 70.63% of Python3 online submissions for Excel Sheet Column Title. | |
""" | |
if columnNumber <= 26: | |
return chr(64+columnNumber) | |
left = columnNumber // 26 | |
right = columnNumber % 26 | |
if (right == 0): | |
left = (left -1) if left > 1 else 1 | |
return self.convertToTitle(left) + self.convertToTitle(26) | |
return self.convertToTitle(left) + self.convertToTitle(right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.