当前位置:网站首页>力扣每日一题-第42天-171. Excel表列序号
力扣每日一题-第42天-171. Excel表列序号
2022-07-22 18:51:00 【重邮研究森】
2022.7.22今天你刷题了吗?
题目:
给你一个字符串 columnTitle ,表示 Excel 表格中的列名称。返回 该列名称对应的列序号 。
分析:
给定一个字符串,例如“A”,那么结果=1,“B”=2,“AB”=28=2+26.
那么这其实满足下面这个公式
对于字符串“ABCD”,相当于【1 2 3 4】
那么,可以这样操作:
4x26^0 + 3x26^1+2x26^2+1x26^3=结果
思路:对于字符串,我们依次遍历,写出上诉公式即可。

解析:
class Solution {
public:
int titleToNumber(string columnTitle) {
int n = columnTitle.size();
int ans = 0;
for(int i = 0; i < n; i++){
ans = ans*26+(columnTitle[i] - 'A' + 1);
}
return ans;
}
};边栏推荐
- Learning Pyramid-Context Encoder Network for High-Quality Image Inpainting论文笔记
- Pile up basic exercises - 1
- Image Inpainting for Irregular Holes Using Partial Convolutions 论文笔记
- If there is only express delivery order number, how to query the logistics progress and check the order number of the delivery
- Liu Jingjuan, Deputy Secretary General of the open atom open source foundation: Thoughts on the current situation and trend of open source development in China
- node使用exec方法开启子进程
- 中年危机提前来临的一代人,还能够从容生活吗?
- Ni Guangnan, academician of the Chinese Academy of Engineering: embrace open source and world collaborative innovation
- Centos7 installing and uninstalling mysql5.7
- 最新可用的二维码生成 api
猜你喜欢

Memory allocation of string in JVM

JS complex data type

Tan Zhongyi, the initiator of xingce community: promote the intelligent transformation of enterprises by means of open source

Stack overflow basic exercise - 4 (there are 64 and 32-bit attacks)

Which one works better, Yapi or apifox? In depth analysis of the functional features of Yapi and apifox

XML架构

urllib下载(urlretrieve())

我的代码-极速版

第6.3章:ARM架构下手动编译StarRocks(拓展篇)

视频去除色彩,教你简单不复杂的操作方法
随机推荐
微信小程序开发:第一个helloWorld
R语言绘制 空间可视化
如何打包你的项目并且可以让别的用户通过pip安装
OSPF相关内容
安装不了schedule
Dao smart contract DAPP system development technology
MGRE与OSPF综合实验
urllib下载(urlretrieve())
OSPF related content
Iqiyi opens the authorization to Tiktok and opens a new door to the value of content
pwn ——ret2libc3
MNIST dataset
使用mediapipe和OpenCV 实现简单人脸检测
[basic 4] - document reading and writing, module
MySql 事务及其带来的问题和隔离级别
最新可用的二维码生成 api
兆易创新GD25WDxxK6 SPI NOR Flash产品系列问世
Globally and Locally Consistent Image Completion 论文笔记
MySq 数据库约束
Introduction to distributed learning and federated learning