当前位置:网站首页>168. excel table column name
168. excel table column name
2022-07-01 03:43:00 【Sun_ Sky_ Sea】
168. Excel Table column name
Original title link :https://leetcode.cn/problems/excel-sheet-column-title/
Give you an integer columnNumber , Back to it in Excel The name of the corresponding column in the table .
for example :
A -> 1
B -> 2
C -> 3
…
Z -> 26
AA -> 27
AB -> 28
…
Example 1:
Input :columnNumber = 1
Output :“A”
Example 2:
Input :columnNumber = 28
Output :“AB”
Example 3:
Input :columnNumber = 701
Output :“ZY”
Example 4:
Input :columnNumber = 2147483647
Output :“FXSHRXW”
Their thinking :
Calculate the corresponding letter from low to high by calculating the remainder and quotient , here 26 The radix calculation is 0 To 25 This 26 Number , but A It's from 1 At the beginning , So when calculating the remainder and quotient , In order to be able to communicate with 26 The base number remains the same , So subtract it first 1, Calculate again .
Code implementation :
class Solution:
def convertToTitle(self, columnNumber: int) -> str:
ans = []
while columnNumber > 0:
# the reason being that 26 Base number :0~25, but A It's from 1 At the beginning , So the letters are relative to the normal 26 Decimal digit
# Added one more 1, So it's using 26 In hexadecimal calculation , First subtract 1 individual 1
columnNumber -= 1
# Calculate the remainder , The rightmost letter
cur = columnNumber % 26
# Convert letters
cur_ans = chr(cur + ord('A'))
ans.insert(0, cur_ans)
# Seeking quotient , Calculate the next letter
columnNumber //= 26
return ''.join(ans)
reference :
https://leetcode.cn/problems/excel-sheet-column-title/solution/excelbiao-lie-ming-cheng-by-leetcode-sol-hgj4/
边栏推荐
- 【TA-霜狼_may-《百人计划》】2.1 色彩空间
- The difference between MFC for static libraries and MFC for shared libraries
- The combination of applet container technology and IOT
- Complete knapsack problem
- 在 C 中声明函数之前调用函数会发生什么?
- [nine day training] content III of the problem solution of leetcode question brushing Report
- 【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
- [party benefits] jsonobject to string, leave blank
- Leetcode: offer 59 - I. maximum value of sliding window
- 整合阿里云短信的问题:无法从静态上下文中引用非静态方法
猜你喜欢
Avalanche problem and the use of sentinel
Ridge regression and lasso regression
Feature pyramid networks for object detection
Idea plug-in backup table
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
Cookie&Session
Edlines: a real time line segment detector with a false detection control
The difference between MFC for static libraries and MFC for shared libraries
Valentine's Day is nothing.
4. [WebGIS practice] software operation chapter - data import and processing
随机推荐
TEC: Knowledge Graph Embedding with Triple Context
谷粒学院微信扫码登录过程记录以及bug解决
Leetcode: offer 59 - I. maximum value of sliding window
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
Review column - message queue
205. 同构字符串
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
Leetcode:829. Sum of continuous integers
Promql select time series
171. Excel 表列序号
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
Filter
用小程序的技术优势发展产业互联网
【TA-霜狼_may-《百人计划》】1.3纹理的秘密
在 C 中声明函数之前调用函数会发生什么?
深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)
Future of NTF and trends in 2022
后台系统页面左边菜单按钮和右边内容的处理,后台系统页面出现双滚动
10. 正则表达式匹配