Given a column title as appear in an Excel sheet, return its corresponding column number.

For example:


    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28 
    ...


Example 1:


Input: "A"
Output: 1


Example 2:


Input: "AB"
Output: 28


Example 3:


Input: "ZY"
Output: 701

Source: leetcode | Difficulty: EASY
Tags: String algorithms

Mathematics

Starter code: class Solution:
    def titleToNumber(self, s: str) -> int:
        

Solutions:
class Solution:

	def titleToNumber(self, s):
		(r, t) = (0, 1)
		for i in s:
			r = r * 26 + (ord(i) - 64)
		return r


class Solution:

	def titleToNumber(self, s):
		res = 0
		for i in s:
			res = res * 26 + ord(i) - ord('A') + 1
		return res


class Solution:

	def titleToNumber(self, s):
		result = 0
		for char in s:
			result *= 26
			result += ord(char) - ord('A') + 1
		return result


class Solution:

	def titleToNumber(self, s):
		return 0 if len(s) == 0 else ord(s[-1]) - ord('A') + 1 + 26 * self.titleToNumber(s[:len(s) - 1])


class Solution:

	def titleToNumber(self, s):
		s = s[::-1]
		sum = 0
		for (exp, char) in enumerate(s):
			sum += (ord(char) - 65 + 1) * 26 ** exp
		return sum


class Solution:

	def titleToNumber(self, s):
		s = [ord(c) - 64 for c in s]
		result = 0
		x = len(s) - 1
		for i in range(0, len(s)):
			result += s[x - i] * 26 ** i
		return result


class Solution:

	def titleToNumber(self, s):
		val = ord('A')
		length = len(s)
		sum = 0
		for i in range(length):
			sum = sum + (ord(s[i]) - val + 1) * 26 ** (length - 1 - i)
		return sum


class Solution:

	def titleToNumber(self, s):
		s = s[::-1]
		res = 0
		for (exp, c) in enumerate(s):
			res += (ord(c) - 65 + 1) * 26 ** exp
		return res