leetcode 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 
class Solution { public: int titleToNumber(string s) { int l=s.length(); int n=0; for(int i=l-1;i>=0;i--) { n+=(s[i]-'A'+1)*pow(26,l-i-1); } return n; } };

猜你喜欢

转载自blog.csdn.net/vinacky/article/details/51540479