当前位置:网站首页>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.3 常用函数介绍
- LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
- Golang multi graph generation gif
- 在线公网安备案保姆级教程【伸手党福利】
- [small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation
- Explain spark operation mode in detail (local+standalone+yarn)
- What happens when a function is called before it is declared in C?
- Thread data sharing and security -threadlocal
- 排序链表(归并排序)
- 241. 为运算表达式设计优先级
猜你喜欢
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
Edlines: a real time line segment detector with a false detection control
Asgnet paper and code interpretation 2
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
Blueprism registration, download and install -rpa Chapter 1
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
Sort linked list (merge sort)
C语言的sem_t变量类型
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
随机推荐
Error: plug ins declaring extensions or extension points must set the singleton directive to true
数据库中COMMENT关键字的使用
Finally in promise
214. 最短回文串
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
Valid brackets (force deduction 20)
FCN全卷積網絡理解及代碼實現(來自pytorch官方實現)
jeecgboot输出日志,@Slf4j的使用方法
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
[reach out to Party welfare] developer reload system sequence
Appium自动化测试基础--补充:C/S架构和B/S架构说明
[daily training] 1175 Prime permutation
30. 串联所有单词的子串
How keil displays Chinese annotations (simple with pictures)
【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
FCN全卷积网络理解及代码实现(来自pytorch官方实现)
Appium fundamentals of automated testing - basic principles of appium
静态库使用MFC和共享库使用MFC的区别
【TA-霜狼_may-《百人计划》】2.1 色彩空间
6. Z 字形变换