Created
August 10, 2020 21:25
-
-
Save munguial/0d122ac059fbc1435a367fa82b65aada to your computer and use it in GitHub Desktop.
August - Day 10 - Excel Sheet 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
# https://leetcode.com/explore/featured/card/august-leetcoding-challenge/550/week-2-august-8th-august-14th/3419/ | |
class Solution: | |
def titleToNumber(self, s: str) -> int: | |
res = 0 | |
power = 0 | |
for i in reversed(range(len(s))): | |
res += int(ord(s[i]) - ord('A') + 1) * (26**power) | |
power += 1 | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment