LeetCode-171. Excel Sheet Column Number

来源:互联网 发布:udid授权软件 编辑:程序博客网 时间:2024/06/05 20:25

问题:https://leetcode.com/problems/excel-sheet-column-number/?tab=Description
Related to question Excel Sheet Column Title。
Given a column title as appear in an Excel sheet, return its corresponding column number.
给定一个Excel表格中的列标题,返回对应的列号。
For example:
A -> 1
B -> 2
C -> 3

Z -> 26
AA -> 27
AB -> 28
**分析:**26进制转化为10进制。
C++代码:

class Solution {public:    int titleToNumber(string s) {        int l=s.size();        int res=0;        for(int i=0;i<l;i++){            res=res*26+(s[i]-'A'+1);        }        return res;    }};
0 0