当前位置:网站首页>171. excel table column No
171. excel table column No
2022-07-01 03:43:00 【Sun_ Sky_ Sea】
171. Excel Table column No
Original title link :https://leetcode.cn/problems/excel-sheet-column-number/
Give you a string columnTitle , Express Excel Column names in the table . return The column sequence number corresponding to the column name .
for example :
A -> 1
B -> 2
C -> 3
…
Z -> 26
AA -> 27
AB -> 28
…
Example 1:
Input : columnTitle = “A”
Output : 1
Example 2:
Input : columnTitle = “AB”
Output : 28
Example 3:
Input : columnTitle = “ZY”
Output : 701
Tips :
1 <= columnTitle.length <= 7
columnTitle Composed of capitalized English only
columnTitle In scope [“A”, “FXSHRXW”] Inside
Their thinking :
This question is to 26 Hexadecimal letters are converted into corresponding decimal numbers , First convert the letters to the corresponding 26 Base integers , Then multiply these integers by the corresponding base number from low to high , convert to 10 Hexadecimal number , Pay attention here columnTitle The rightmost letter is the lowest order , A flashback traversal is required .
Code implementation :
class Solution:
def titleToNumber(self, columnTitle: str) -> int:
ans = 0
# 26 Base of base
mul = 1
# Flashback traversal columnTitle, Because the smallest number is on the far right
for i in range(len(columnTitle) - 1, -1, -1):
# To convert to decimal numbers , To calculate ASCII Value
cur = ord(columnTitle[i]) - ord('A') + 1
ans += cur * mul
mul *= 26
return ans
reference :
https://leetcode.cn/problems/excel-sheet-column-number/solution/excelbiao-lie-xu-hao-by-leetcode-solutio-r29l/
边栏推荐
- Go tool cli for command line implementation
- Thread data sharing and security -threadlocal
- Appium自动化测试基础--补充:C/S架构和B/S架构说明
- [party benefits] jsonobject to string, leave blank
- Split(), split(), slice(), can't you tell?
- Pyramid scene parsing network [pspnet] thesis reading
- 整合阿里云短信的问题:无法从静态上下文中引用非静态方法
- Pyramid Scene Parsing Network【PSPNet】论文阅读
- 【TA-霜狼_may-《百人计划》】1.3纹理的秘密
- 深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
猜你喜欢

pytorch训练深度学习网络设置cuda指定的GPU可见

Addition without addition, subtraction, multiplication and division

pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear

Feature pyramid networks for object detection

pytorch nn. AdaptiveAvgPool2d(1)

FCN全卷积网络理解及代码实现(来自pytorch官方实现)

谷粒学院微信扫码登录过程记录以及bug解决

Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page

Pytorch training deep learning network settings CUDA specified GPU visible

Review column - message queue
随机推荐
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
Md5sum operation
Valid brackets (force deduction 20)
pytorch训练深度学习网络设置cuda指定的GPU可见
谷粒学院微信扫码登录过程记录以及bug解决
Cookie&Session
jeecgboot输出日志,@Slf4j的使用方法
409. 最长回文串
208. 实现 Trie (前缀树)
torch. histc
4. [WebGIS practice] software operation chapter - data import and processing
不用加减乘除实现加法
小程序容器技术与物联网IoT的结合点
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
205. 同构字符串
Complete knapsack problem
用小程序的技术优势发展产业互联网
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
Use of comment keyword in database