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;
    }
};
相关推荐
青草地溪水旁18 小时前
C++中的Reactor和Proactor模型进行系统性解析
c++·网络编程‘
云天徽上18 小时前
【数据可视化-106】华为2025上半年财报分析:用Python和Pyecharts打造炫酷可视化大屏
开发语言·python·华为·信息可视化·数据分析·pyecharts
AMiner:AI科研助手18 小时前
警惕!你和ChatGPT的对话,可能正在制造分布式妄想
人工智能·分布式·算法·chatgpt·deepseek
墩墩分墩21 小时前
【Go语言入门教程】 Go语言的起源与技术特点:从诞生到现代编程利器(一)
开发语言·后端·golang·go
深耕AI21 小时前
【MFC中OnInitDialog虚函数详解:哪个是虚函数?两个OnInitDialog的关系】
c++·mfc
CHANG_THE_WORLD21 小时前
并发编程指南 同步操作与强制排序
开发语言·c++·算法
pl002021 小时前
C++虚函数&虚析构函数&纯虚函数的使用说明和理解
c++·虚函数·纯虚函数·虚析构函数
仰泳之鹅1 天前
【C语言】深入理解指针(5)
c语言·开发语言
gaoshou451 天前
代码随想录训练营第三十一天|LeetCode56.合并区间、LeetCode738.单调递增的数字
数据结构·算法