当前位置:网站首页>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/
边栏推荐
- jeecgboot输出日志,@Slf4j的使用方法
- Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
- 4、【WebGIS实战】软件操作篇——数据导入及处理
- Jeecgboot output log, how to use @slf4j
- Appium fundamentals of automated testing - basic principles of appium
- 【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
- The combination of applet container technology and IOT
- 用小程序的技术优势发展产业互联网
- BluePrism注册下载并安装-RPA第一章
- Detailed explanation of ES6 deconstruction grammar
猜你喜欢

Error: plug ins declaring extensions or extension points must set the singleton directive to true

快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内

报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
![[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理

pytorch nn.AdaptiveAvgPool2d(1)

Feature pyramid networks for object detection

深度学习中的随机种子torch.manual_seed(number)、torch.cuda.manual_seed(number)

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

Download and installation configuration of cygwin

Edlines: a real time line segment detector with a false detection control
随机推荐
【伸手党福利】开发人员重装系统顺序
Gorilla/mux framework (RK boot): RPC error code design
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
30. 串联所有单词的子串
Detailed explanation of ES6 deconstruction grammar
[TA frost wolf \u may - "hundred people plan"] 2.1 color space
Jeecgboot output log, how to use @slf4j
Pytorch training deep learning network settings CUDA specified GPU visible
Feature pyramid networks for object detection
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
pytorch nn. AdaptiveAvgPool2d(1)
Implement pow (x, n) function
Appium自动化测试基础--补充:C/S架构和B/S架构说明
AfxMessageBox和MessageBox的用法
Binary tree god level traversal: Morris traversal
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
Explain spark operation mode in detail (local+standalone+yarn)
【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
214. 最短回文串
Cookie&Session