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;
    }
};
相关推荐
算AI1 分钟前
基于LLM的无人机仿真测试:新方法竞赛夺佳绩
人工智能·深度学习·算法·机器学习·ai
oh,huoyuyan25 分钟前
JS 动态网页抓不到?试试火车采集器网页抓取工具
开发语言·javascript·ecmascript
风流 少年43 分钟前
hutool
java·服务器·开发语言
kaixin_啊啊1 小时前
专用优化算法LKH
算法
一木 之林1 小时前
四、STL容器与数据结构
开发语言·数据结构·c++
QX_hao1 小时前
【Go】--Cobra-cli的用法
开发语言·后端·golang
程与留1 小时前
07_QMainWindow 与应用程序框架——菜单栏、工具栏、状态栏
c++·qt
艾醒(AiXing-w)1 小时前
LangChain 1.0 入门(三):稳定性双核心——重试机制+速率限速器参数详解与实战
开发语言·langchain·php
总有刁民想爱朕ha2 小时前
Python PyQt5图片批量转MP4视频工具:本地离线免费无水印,完整代码
开发语言·python·qt
宸津-代码粉碎机2 小时前
FastUtil+AI多Agent实战:Java AI项目性能终极加速方案
java·服务器·开发语言·python·安全·php