当前位置:网站首页>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/
边栏推荐
- pytorch nn.AdaptiveAvgPool2d(1)
- Ouc2021 autumn - Software Engineering - end of term (recall version)
- 快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
- [深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
- [TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
- ASGNet论文和代码解读2
- Error: plug ins declaring extensions or extension points must set the singleton directive to true
- AfxMessageBox和MessageBox的用法
- 后台系统右边内容如何出现滚动条和解决双滚动条的问题
- Binary tree god level traversal: Morris traversal
猜你喜欢
SEM of C language_ Tvariable type
IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
MFC窗口滚动条用法
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
Blueprism registration, download and install -rpa Chapter 1
复习专栏之---消息队列
随机推荐
Golang multi graph generation gif
Sort linked list (merge sort)
Blueprism registration, download and install -rpa Chapter 1
TEC: Knowledge Graph Embedding with Triple Context
torch. histc
392. 判断子序列
TEC: Knowledge Graph Embedding with Triple Context
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
【TA-霜狼_may-《百人计划》】2.1 色彩空间
[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation
Leetcode:829. 连续整数求和
Addition without addition, subtraction, multiplication and division
Appium自动化测试基础 — APPium基本原理
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
bootsrap中的栅格系统
389. 找不同
318. 最大单词长度乘积
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
4. [WebGIS practice] software operation chapter - data import and processing