# 171. Excel Sheet Column Number

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

# Solution

Approach 1: Scan the string and calculate.

# Code (Python)

Approach 1:

# Code (C++)

Approach 1:

class Solution {
public:
    int titleToNumber(string s) {
        int number = 0;
        int level = 1;
        for (int i = s.size() - 1; i >= 0; --i)
        {
            number += (s[i] - 'A' + 1) * level;
            level *= 26;
        }
        return number;
    }
};

class Solution {
public:
    int titleToNumber(string s) {
        int number = 0;
        for (int i = 0; i < s.size(); ++i)
        {
            number = number * 26 + (s[i] - 'A' + 1);
        }
        return number;
    }
};