当前位置:网站首页>leetcode-168.Excel表列名称
leetcode-168.Excel表列名称
2022-07-23 13:03:00 【KGundam】
数学问题
题目详情
给你一个整数 columnNumber ,返回它在 Excel 表中相对应的列名称。
例如:
A -> 1
B -> 2
C -> 3
…
Z -> 26
AA -> 27
AB -> 28
…
示例1:
输入:columnNumber = 1
输出:"A"
示例2:
输入:columnNumber = 28
输出:"AB"
示例3:
输入:columnNumber = 701
输出:"ZY"
示例4:
输入:columnNumber = 2147483647
输出:"FXSHRXW"
思路:
很明显可以看出这是一道26进制转换问题,但是需要注意的是从1开始没有0
因为从1开始,所以我们可以对每个数减一操作,从而使126变成025
从而完全符合了26进制转换规则
我的代码:
class Solution
{
public:
string convertToTitle(int columnNumber)
{
string res;
while (columnNumber > 0)
{
--columnNumber; //整体减一
res += columnNumber % 26 + 'A'; //每次判断对应哪个字母然后接在后面(反的)
columnNumber /= 26;
}
reverse(res.begin(), res.end()); //反转得到正确结果
return res;
}
};
边栏推荐
- Satisfiability of the equation of leetcode
- 国产AI蛋白质结构预测再现突破,用单条序列解决3D结构,彭健团队:“AlphaFold2以来最后一块拼图补齐了”...
- Nifi 1.16.3 cluster setup +kerberos+ user authentication
- Thermal resistance temperature acquisition based on USB data acquisition card (DAQ) and IO module "suggestions collection"
- Bag of Tricks for Image Classification with Convolutional Neural Networks(卷积神经网络在图像分类中的技巧)
- C#入门系列(二十八) -- LINQ的查询语法
- Why does fatal always appear when using opengaussjdbc? (tag database keyword user)
- ESP8266-NodeMCU——从苏宁API获取实时天气
- Niuke-top101-bm36
- 单片机内部IO口保护电路及IO口电气特性以及为什么不同电压IO之间为什么串联一个电阻?
猜你喜欢

VMware platform STS certificate expired

Bag of Tricks for Image Classification with Convolutional Neural Networks(卷积神经网络在图像分类中的技巧)

COPU副主席刘澎:中国开源在局部领域已接近或达到世界先进水平

32位单片机GPIO端口电路结构以及输出模式

FIO performance testing tool

卷积神经网络模型之——GoogLeNet网络结构与代码实现

Flutter | 给 ListView 添加表头表尾最简单的方式

【C语言】结构体、枚举和联合体

The competition boss is in Huawei: network experts are from Stanford physics department, and some people "work as much as reading a doctoral degree"

机器狗背冲锋枪射击视频火了,网友瑟瑟发抖:stooooooooppppp!
随机推荐
CNCF基金会总经理Priyanka Sharma:一文读懂CNCF运作机制
Why does fatal always appear when using opengaussjdbc? (tag database keyword user)
聊一聊JVM的内存布局
MySQL multi table query_ Cartesian product_ Inner connection_ Implicit connection
(已解决)idea编译Gradle项目提示 错误找不到符号
中国化NFT?NFR横空出世
The working principle of PLL. For example, how can our 8MHz crystal oscillator make MCU work at 48mhz or 72mhz
【Error】TypeError: expected str, bytes or os.PathLike object, not int
国内生产总值(GDP)数据可视化
2022-7-22 面经复习+简单题目整理
Talk about the memory layout of JVM
The competition boss is in Huawei: network experts are from Stanford physics department, and some people "work as much as reading a doctoral degree"
tensorflow一层神经网络训练手写体数字识别
VMware platform STS certificate expired
Several common SQL misuses in MySQL
20220721 beaten content
深度学习卷积神经网络论文研读-AlexNet
Go interface: go deep into internal principles
Calendar日历类
Dynamic programming knapsack problem 01 knapsack explanation