Skip to content

Latest commit

 

History

History
executable file
·
39 lines (31 loc) · 1.5 KB

171. Excel Sheet Column Number.md

File metadata and controls

executable file
·
39 lines (31 loc) · 1.5 KB

#

一天一道LeetCode

本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 ##(一)题目

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

##(二)解题

题目大意:将EXCEL里面的sheet栏号转换成对应的数字。

解题思路:excel栏号是以26为一个循环,因此执行一个26进制转换就行。

class Solution {
public:
    int titleToNumber(string s) {
        int len = s.length();
        int ret = 0;
        for(int i = 0 ; i<len ;i++){
            ret = ret*26+(s[i]-&#39;A&#39;+1);//26进制
        }
        return ret;
    }
};