LeetCode 171 Excel Sheet Column Number 解题报告
题目要求
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表格中的列标题,要求返回对应的列数字(正如例子所示)。其实这相当于一个进制问题,逢27进一。可以遍历字符串中的每个字符,将每个字符对应值乘以对应权重所得结果求和即为该字符串对应的数字。
python代码
class Solution:
def titleToNumber(self, s: str) -> int:
ans = 0
l = len(s)
for i,v in enumerate(s):
ans += (ord(v) - 64)*(26**(l-i-1))
return ans
LeetCode 171 Excel Sheet Column Number 解题报告的更多相关文章
- 【LeetCode】171. Excel Sheet Column Number 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目大意 解题方法 Java解法 Python解法 日期 [LeetCode] 题 ...
- [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 ...
- Java for LeetCode 171 Excel Sheet Column Number
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- 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 ...
- ✡ leetcode 171. Excel Sheet Column Number 字母转换为数字 --------- java
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- LeetCode: 171 Excel Sheet Column Number(easy)
题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...
- LeetCode 171 Excel Sheet Column Number
Problem: Given a column title as appear in an Excel sheet, return its corresponding column number. F ...
- Leetcode 171 Excel Sheet Column Number python
题目: Given a column title as appear in an Excel sheet, return its corresponding column number. For ex ...
- 20. leetcode 171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...
随机推荐
- Hack Programming
计算机由ROM(instruction memory).RAM(data memory).CPU组成,其关系如下图 在计算中存在3种寄存器:D.A.M.其中D是data register,A是addr ...
- 10张思维导图带你学习JavaScript
10张思维导图带你学习JavaScript 下面将po出10张JavaScript相关的思维导图. 分别归类为: JavaScript变量 JavaScript运算符 JavaScript数组 ...
- IIS命令行静默安装脚本-python
#coding=utf8 import platform from subprocess import Popen,PIPE,STDOUT import sys,os def run_cmd(cmd, ...
- Visual studio 编辑combobox程序卡死的问题
问题描述:使用vs2017开发一个winform小程序,一用combobox就卡死. 问题解决:关闭有道词典的取词功能. 软件开多了,就容易有冲突啊!
- 著名的3像素Bug(div+img,多出几像素)
<div><img src="...."></div> 给img的css设置display: block;/*用来去除div下边莫名多出来的3p ...
- docker部署项目 <三>
使用docker运行一个控制台项目,新建一个控制台测试项目 一.安装mono,直接在网易镜像中心找下载路径 docker pull hub.c..com/library/mono:latest 二.安 ...
- 关闭 Visual Studio 的 Browser Link 功能
最近公司弄新项目需要用 MVC,就把 IDE 升级到了 Visual Studio 2013,在开发的时候发现有好多请求一个本地49925的端口 . 很奇怪,一开始以为是 Visual Studio ...
- spark_to_es
package es import java.io.InputStream import java.text.SimpleDateFormat import java.util.{Calendar, ...
- Problem J. Journey with Pigs
Problem J. Journey with Pigshttp://codeforces.com/gym/241680/problem/J考察排序不等式算出来单位重量在每个村庄的收益,然后生序排列猪 ...
- P1516 青蛙的约会
P1516 青蛙的约会x+mt-p1L=y+nt-p2L(m-n)t+L(p2-p1)=y-x令p=p2-p1(m-n)t+Lp=y-x然后套扩欧就完事了 #include<iostream&g ...