[LeetCode]--171. Excel Sheet Column Number

简介: Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -&

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.

问题应该并不复杂,就跟String转int一样,只是这是个26进制的数而已。

public int titleToNumber(String s) {
        if (s.length() == 0 || s == null)
            return 0;
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum = sum * 26 + (s.charAt(i) - 'A' + 1);
        }
        return sum;
    }

一次就Accept!

目录
相关文章
|
8天前
|
easyexcel
【EasyExcel】第二篇:导出excel文件,导出多个sheet工作空间
【EasyExcel】第二篇:导出excel文件,导出多个sheet工作空间
|
6月前
|
算法
Leetcode 313. Super Ugly Number
题目翻译成中文是『超级丑数』,啥叫丑数?丑数就是素因子只有2,3,5的数,7 14 21不是丑数,因为他们都有7这个素数。 这里的超级丑数只是对丑数的一个扩展,超级丑数的素因子不再仅限于2 3 5,而是由题目给定一个素数数组。与朴素丑数算法相比,只是将素因子变了而已,解法还是和朴素丑数一致的。
66 1
|
8天前
|
存储 算法
【LeetCode力扣】单调栈解决Next Greater Number(下一个更大值)问题
【LeetCode力扣】单调栈解决Next Greater Number(下一个更大值)问题
8 0
|
8天前
|
存储 数据处理 Python
使用Python批量合并Excel文件的所有Sheet数据
使用Python批量合并Excel文件的所有Sheet数据
41 0
|
8天前
|
数据处理 Python
4种方法用Python批量实现多Excel多Sheet合并
4种方法用Python批量实现多Excel多Sheet合并
81 0
|
7月前
【Leetcode-171.Excel表列序号 -168.Excel表列名称】
【Leetcode-171.Excel表列序号 -168.Excel表列名称】
26 0
|
8天前
|
Java
|
8天前
|
easyexcel Java 数据库
excel多sheet页的导入
excel多sheet页的导入
|
8天前
|
算法 vr&ar 图形学
☆打卡算法☆LeetCode 171. Excel 表列序号 算法解析
☆打卡算法☆LeetCode 171. Excel 表列序号 算法解析
|
8天前
|
算法 vr&ar 图形学
☆打卡算法☆LeetCode 168. Excel表列名称 算法解析
☆打卡算法☆LeetCode 168. Excel表列名称 算法解析