[leetcode]Excel Sheet Column Number

来源:互联网 发布:知乎 微星台式机 编辑:程序博客网 时间:2024/05/19 21:18

Related to question Excel Sheet Column Title

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

class Solution {public:    int titleToNumber(string s) {        int n= s.length(),cnt=0;        for(int i=0;i<n;i++){            cnt*=26;            cnt+=s[i]-'A'+1;        }        return cnt;    }};
0 0
原创粉丝点击