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.

168. Excel Sheet Column Title 的类似题目,这次是给出列的题目,返回对应的数字。

Python:

class Solution(object):
def titleToNumber(self, s):
result = 0
for i in xrange(len(s)):
result *= 26
result += ord(s[i]) - ord('A') + 1
return result

C++:

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;
}
};

 

类似题目:

[LeetCode] 168. Excel Sheet Column Title 求Excel表列名称

 

All LeetCode Questions List 题目汇总

  

[LeetCode] 171. Excel Sheet Column Number 求Excel表列序号的更多相关文章

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

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

  2. [LeetCode] 168. Excel Sheet Column Title 求Excel表列名称

    Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...

  3. [LeetCode] Excel Sheet Column Title 求Excel表列名称

    Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...

  4. LeetCode 171. Excel Sheet Column Number (Excel 表格列数字)

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

  5. LeetCode 171. Excel表列序号(Excel Sheet Column Number) 22

    171. Excel表列序号 171. Excel Sheet Column Number 题目描述 给定一个 Excel 表格中的列名称,返回其相应的列序号. 每日一算法2019/5/25Day 2 ...

  6. LeetCode Javascript实现 100. Same Tree 171. Excel Sheet Column Number

    100. Same Tree /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; ...

  7. leetcode 168. Excel Sheet Column Title 171 Excel Sheet Column Number

    题目 //像10进制一样进行 转换   只是要从0开始记录 class Solution { public: string convertToTitle(int n) { char a; string ...

  8. 【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number

    168 - Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...

  9. 171. Excel Sheet Column Number(C++)

    171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...

随机推荐

  1. 使用Arduino连接HC-SR04超声波距离传感器的方法

    距离传感器是机器人项目最有用的传感器之一. HC-SR04是一种便宜的超声波距离传感器,可以帮助您的机器人在房间周围导航.通过一些努力和一个额外的组件,它也可以用作测量设备.在这篇文章中,您将学习到通 ...

  2. 剑指Offer(二十):包含min函数的栈

    剑指Offer(二十):包含min函数的栈 搜索微信公众号:'AI-ming3526'或者'计算机视觉这件小事' 获取更多算法.机器学习干货 csdn:https://blog.csdn.net/ba ...

  3. Codeforces B. Too Easy Problems

    题目描述: time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  4. centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

    客户端连接报错 这个问题是因为用户在数据库服务器中的mysql数据库中的user的表中没有权限. 解决步骤 1.连接服务器: mysql -u root -p 2.看当前所有数据库:show data ...

  5. webpack的loader的原理和实现

    想要实现一个loader,需要首先了解loader的基本原理和用法. 1. 使用 loader是处理模块的解析器. module: { rules: [ { test: /\.css$/, use: ...

  6. 【区间DP】加分二叉树

    https://www.luogu.org/problemnew/show/P1040#sub 题目描述 设一个n个节点的二叉树tree的中序遍历为(1,2,3,…,n),其中数字1,2,3,…,n为 ...

  7. 虚拟变量和独热编码的区别(Difference of Dummy Variable & One Hot Encoding)

    在<定量变量和定性变量的转换(Transform of Quantitative & Qualitative Variables)>一文中,我们可以看到虚拟变量(Dummy Var ...

  8. Theano入门笔记1:Theano中的Graph Structure

    译自:http://deeplearning.net/software/theano/extending/graphstructures.html#graphstructures 理解Theano计算 ...

  9. socket简单实践

    目录 socket模块: family(socket家族) fileno=None 请忽略,特殊用途 socket模块: 把tcp/ip协议层的各种数据封装啦.数据发送.接收等通过代码已经给你封装 应 ...

  10. react用脚手架创建一个react单页面项目,react起手式

    官网地址:https://react.docschina.org/ 确保本地安装了Node.js node的版本大于8.10    npm的版本大于5.6 1.在本地的某个位置创建一个文件夹,执行以下 ...