Tuesday, August 25, 2015

Leetcode 171. Excel Sheet Column Number

https://leetcode.com/problems/excel-sheet-column-number/

This is the reverse operation of problem 168.

Solution:
# T:O(n) S:O(1)
class Solution:
    # @param s, a string
    # @return an integer
    def titleToNumber(self, s):
        result = 0
        for i in xrange(len(s)):
            result *= 26
            result += ord(s[i]) - ord('A') + 1
        return result
Run Time: 60 ms

No comments:

Post a Comment