Another python code beats 100%


  • 0
    C

    I first used reduce, lambda, etc, ... any python user always like those little tricks

    Then I did it in a straight way, it beats 100% python, 48ms

    I found this more than once that straight code beats fancy code

    def titleToNumber(self, s):
            res =0
            if not s: return res  
            i = len(s) - 1
            while i >= 0:
                temp = ord(s[i]) - ord('A') + 1 
    # or temp = ord(s[i]) - 64, may be faster
                res += temp * 26**(len(s)-1-i)
                i -= 1            
            return res
    

Log in to reply
 

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