【leetcode】171. Excel Sheet Column Number

题目:
Given a column title as appear in an Excel sheet, return its corresponding column number.


思路:
很简单,直接看代码就好。


代码实现:

class Solution {
public:
    int char2Int(char c){
        return c-'A'+1;
    }
    
    int titleToNumber(string s) {
        int sum = char2Int(s[0]);
        
        for (int i = 1; i < s.size(); ++i){
            sum = sum * 26 + char2Int(s[i]);
        }
        
        return sum;
    }
};
原创文章 299 获赞 2 访问量 1万+

猜你喜欢

转载自blog.csdn.net/zxc120389574/article/details/106020892