[LeetCode] Excel Sheet Column Number 求Excel表列序号

简介:

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 

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

这题实际上相当于一种二十六进制转十进制的问题,并不难,只要一位一位的转换即可。代码如下:

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

本文转自博客园Grandyang的博客,原文链接:求Excel表列序号[LeetCode] Excel Sheet Column Number ,如需转载请自行联系原博主。

相关文章
|
3月前
|
C++
Excel 表列序号(C++)
Excel 表列序号(C++)
22 0
|
3月前
leetcode-1331:数组序号转换
leetcode-1331:数组序号转换
34 0
|
13天前
【力扣】168. Excel表列名称、171. Excel 表列序号
【力扣】168. Excel表列名称、171. Excel 表列序号
|
1月前
|
存储 数据处理 Python
使用Python批量合并Excel文件的所有Sheet数据
使用Python批量合并Excel文件的所有Sheet数据
33 0
|
1月前
|
数据处理 Python
4种方法用Python批量实现多Excel多Sheet合并
4种方法用Python批量实现多Excel多Sheet合并
39 0
|
2月前
|
Java
|
3月前
|
Java 算法 Go
Java每日一练(20230330) Excel表列序号、最大数、颜色分类
Java每日一练(20230330) Excel表列序号、最大数、颜色分类
31 0
Java每日一练(20230330) Excel表列序号、最大数、颜色分类
|
4月前
|
easyexcel Java 数据库
excel多sheet页的导入
excel多sheet页的导入
|
1月前
|
机器学习/深度学习 算法
力扣刷题日常(一)
力扣刷题日常(一)
20 2
|
1月前
|
存储 索引
《LeetCode》—— LeetCode刷题日记
《LeetCode》—— LeetCode刷题日记