LeetCode 171. Excel表列序号

原创 2018年04月15日 00:50:13

题目描述: Excel表列序号

        与 Excel表列名称 问题类似。

        给定一个Excel表格中的列名称,返回其相应的列序号。

示例:

    A -> 1
    B -> 2
    C -> 3
    ...
    Z -> 26
    AA -> 27
    AB -> 28 

解题思路:

        正常的26进制转10进制

代码:

class Solution {
public:
    int titleToNumber(string s) {
        map<char, int> m;
        for(char i = 'A'; i <= 'Z' ; i ++) {
            m[i] = i-'A'+1;
        }
        
        int ans = 0;
        for(int i = 0 ; i < s.size() ; i ++) {
            ans = ans*26 + m[s[i]];
        }
        return ans;
    }
};

[LeetCode]171. Excel Sheet Column Number(Excel表格列号)

171. Excel Sheet Column Number和168题是一个类型的,参考[LeetCode]168. Excel Sheet Column TitleGiven a column ti...
  • whl_program
  • whl_program
  • 2017-04-18 00:56:24
  • 171

LeetCode 171 Excel Sheet Column Number(Excel的列向表数字)

翻译给定一个出现在Excel表格上的列表标题,返回它的正确行数。 例如: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA ->...
  • NoMasp
  • NoMasp
  • 2016-01-11 21:06:04
  • 1821

leetcode 171. Excel表列序号

#思路就是26进制转10进制,这样一说是不是感觉很简单了呢?class Solution(object): def titleToNumber(self, s): &quot;...
  • Jason__Liang
  • Jason__Liang
  • 2018-03-30 17:13:03
  • 4

LeetCode(171) Excel Sheet Column Number

题目如下: Given a column title as appear in an Excel sheet, return its corresponding column number. For...
  • feliciafay
  • feliciafay
  • 2015-01-02 01:14:49
  • 4540

[LeetCode-171]Excel Sheet Column Number(java)

Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retu...
  • xionghuixionghui
  • xionghuixionghui
  • 2016-10-08 21:14:02
  • 555

171. Excel Sheet Column Number Leetcode Python

Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, ...
  • hyperbolechi
  • hyperbolechi
  • 2015-02-15 01:52:25
  • 867

LeetCode 168 Excel Sheet Column Title(Excel的列向表标题)

翻译给定一个正整数,返回它作为出现在Excel表中的正确列向标题。例如: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> ...
  • NoMasp
  • NoMasp
  • 2016-01-11 19:57:40
  • 3748

171. Excel Sheet Column Number [easy] (Python)

题目链接https://leetcode.com/problems/excel-sheet-column-number/题目原文 Related to question Excel Sheet C...
  • coder_orz
  • coder_orz
  • 2016-05-14 15:53:46
  • 1540

leetcode 171: Excel Sheet Column Number

Excel Sheet Column Number Total Accepted: 1643 Total Submissions: 3860 Related to question Excel...
  • xudli
  • xudli
  • 2014-12-30 02:54:57
  • 2261

Leetcode_171_Excel Sheet Column Number

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/42290079 Given a column title ...
  • pistolove
  • pistolove
  • 2014-12-31 07:19:34
  • 1704
收藏助手
不良信息举报
您举报文章:LeetCode 171. Excel表列序号
举报原因:
原因补充:

(最多只允许输入30个字)