当前位置:网站首页>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/
边栏推荐
- FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
- Detailed explanation of ES6 deconstruction grammar
- 【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
- LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
- [深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
- GCC usage, makefile summary
- 衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
- Pyramid Scene Parsing Network【PSPNet】论文阅读
- Future of NTF and trends in 2022
- [reach out to Party welfare] developer reload system sequence
猜你喜欢

Future of NTF and trends in 2022

IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?

Nacos

Develop industrial Internet with the technical advantages of small programs
![[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理

Test function in pychram

Unexpected token o in JSON at position 1 ,JSON解析问题
![Online public network security case nanny level tutorial [reaching out for Party welfare]](/img/66/d9c848a7888e547b7cb28d84aabc24.png)
Online public network security case nanny level tutorial [reaching out for Party welfare]
![Pyramid scene parsing network [pspnet] thesis reading](/img/05/4645c8a595083479dee6835620335d.png)
Pyramid scene parsing network [pspnet] thesis reading

完全背包问题
随机推荐
不用加减乘除实现加法
The combination of applet container technology and IOT
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
166. 分数到小数
10、Scanner. Next() cannot read spaces /indexof -1
Leetcode: offer 59 - I. maximum value of sliding window
Detailed explanation of ES6 deconstruction grammar
二叉树神级遍历:Morris遍历
241. 为运算表达式设计优先级
205. 同构字符串
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
5、【WebGIS实战】软件操作篇——服务发布及权限管理
Future of NTF and trends in 2022
8. 字符串转换整数 (atoi)
GCC usage, makefile summary
衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
【快捷键】
Leetcode:829. Sum of continuous integers
Filter
Explain spark operation mode in detail (local+standalone+yarn)