Leetcode easy题,一个类似的进制转换题,原题目:

Related to question Excel Sheet Column Title
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

可以看出A=1,B=2。。。Z=26。。。。
解决方案:

int titleToNumber(char* s) {
    int res=0;
    for(int i=0;s[i]!='\0';i++){
        res*=26;
        res+=s[i]-'A'+1;
    }
    return res;
}

这道题算法部分比较简单,不再过多叙述。
待续。。。

 posted on 2015-08-04 12:21  TonyShengTan  阅读(85)  评论(0编辑  收藏  举报