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 resultRun Time: 60 ms
No comments:
Post a Comment