python recursion

  • 0

    There a lot of way to do it and this is definitely not the fastest but I feel like the most straightforward way is recursion or loop.

        def titleToNumber(self, s):
            :type s: str
            :rtype: int
            if len(s) == 1:
                return ord(s) - ord('A') + 1
            return self.titleToNumber(s[:-1])*26 + self.titleToNumber(s[-1])

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.