当前位置:网站首页>力扣每日一题-第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论文笔记
- SFM与MVS区别
- Unable to install schedule
- PWN stack overflow basic exercise - 1
- Centos7 installing and uninstalling mysql5.7
- 【高等数学】函数可微与可导的区别
- Properties of node process object
- R language rendering space visualization
- MNIST dataset
- Why is the mobile phone signal poor when Im instant messaging is developed
猜你喜欢

Dedecms V5.7.97 contain an XSS vulnerability

Linear regression and logical regression and their implementation

eNSP关于OSPF的综合实验

Oracle switches users and queries database commands under linux environment

PWN stack overflow basic exercise - 1

【考研词汇训练营】Day 10 —— capital,expand,force,adapt,depand
![[Fifth space 2019 finals]pwn5 - two solutions](/img/4a/6712ed4d0d274b923db66f0e87cf60.png)
[Fifth space 2019 finals]pwn5 - two solutions

Illustration and text demonstrate the movable range of the applet movable view

selenium报错解决

How to open win11 task manager? Skills and methods of opening win11 Task Manager
随机推荐
怎么为typora配置一个可爱的小鲨鱼主题?
R语言箱线图添加 t.test 显著性-
Image-to-Image Translation with Conditional Adversarial Networks 论文笔记
Live video system source code, save platform video content locally
Source code analysis of robot arm manipulator
OSPF相关内容
Thread类中run和start的区别
Video knowledge points (17) - flv Skills of playing local video files with JS
强化学习2
【考研词汇训练营】Day 10 —— capital,expand,force,adapt,depand
R language drawing oblique diagram
C primer plus学习笔记 —— 5、指针
PWN —— ret2libc1
Derivative in R language
Wechat applet development: the first HelloWorld
What if win11 uses CAD jam or fatal error? Win11 cannot use CAD normally
lasso回归结果美化
H2O R language construction
影響接口查詢速度的情况
Memory allocation of string in JVM