首页 > 代码库 > Leetcode Excel Sheet Column Number

Leetcode 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 

 

 1 class Solution { 2 public: 3     int titleToNumber(string s) { 4         int number = 0; 5         int tmp = 0; 6         for (int i = 0; i < s.length();i++){ 7             tmp = s[i] - A + 1; 8             number = number * 26 + tmp; 9         }10         return number;11         12     }13 };

 

Leetcode Excel Sheet Column Number