leetcode171 Excel Sheet Column Number

题意:

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

思路:找规律,挺简单的···可是小地方错了一些搞了半天···心塞

代码:

int titleToNumber(string s)
{
    int n = s.length();
    int ans = 0;
    for(int i=0;i<n;i++)
    {

        int temp = (int)s[i]-64;
        ans += temp * func(n-i);
    }
    return ans;
}

int func(int n)
{
    if(n==1)
        return 1;
    else
    {
        int res = 1;
        for(int j=0;j<n-1;j++)
            res *= 26;
        return res;
    }

}
原文地址:https://www.cnblogs.com/puyangsky/p/4641883.html