LeetCode168. Excel Sheet Column Title

文章目录

一、题目

Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.

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"

Constraints:

1 <= columnNumber <= 231 - 1

二、题解

cpp 复制代码
class Solution {
public:
    string convertToTitle(int columnNumber) {
        string res;
        while (columnNumber > 0) {
            int a0 = (columnNumber - 1) % 26 + 1;
            res += a0 - 1 + 'A';
            columnNumber = (columnNumber - a0) / 26;
        }
        reverse(res.begin(), res.end());
        return res;
    }
};
相关推荐
yugi987838几秒前
基于Matlab的晴空指数计算实现
开发语言·算法·matlab
song150265372984 分钟前
空间站太阳能帆板电池 组件性能测试 AM0太阳光模拟器
开发语言·python
不会c嘎嘎5 分钟前
QT中的常用控件 (三)
开发语言·qt
代码方舟5 分钟前
Java企业级风控实战:对接天远多头借贷行业风险版API构建信贷评分引擎
java·开发语言
闫有尽意无琼10 分钟前
Qt局部变量“遮蔽(shadow)”成员变量导致lambda传参报错
开发语言·qt
星火开发设计10 分钟前
Python数列表完全指南:从基础到实战
开发语言·python·学习·list·编程·知识·期末考试
另寻沧海12 分钟前
VS Code 内置变量与配置文件完全指南
c++·vscode
工程师00713 分钟前
C# 动态编程(基于 dynamic 类型)
开发语言·c#·dynamic·动态编程
ADI_OP17 分钟前
ADAU1452的开发教程3:常规音频算法的开发(2)
算法·dsp开发·adi dsp中文资料·adi dsp·adi音频dsp·adi dsp开发教程
南桥几晴秋18 分钟前
Qt显示类控件
开发语言·c++·qt