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;
    }
};
相关推荐
阿里嘎多学长3 分钟前
2026-06-07 GitHub 热点项目精选
开发语言·程序员·github·代码托管
字节高级特工3 分钟前
C++11(三)终极指南:可变参数模板与包装器详解
java·开发语言·c++·后端
川冰ICE8 分钟前
JavaScript高级④|类(class)与面向对象,ES6现代写法
开发语言·javascript·es6
Sirius Wu8 分钟前
MoE与Fengyu-Dense_架构对比及训练方案
人工智能·深度学习·算法·机器学习·语言模型·架构
却道天凉_好个秋8 分钟前
HEVC(一):环路滤波
人工智能·算法·计算机视觉·环路滤波
ken223213 分钟前
excel表格为什么越存文件越大? libreoffice 有效
excel
Sirius Wu15 分钟前
Agent模型冷启动问题
开发语言·javascript·人工智能·机器学习·ecmascript·aigc
8Qi816 分钟前
LeetCode 300 & 674:最长递增子序列 vs 最长连续递增子序列
算法·leetcode·职场和发展·动态规划
sheeta199824 分钟前
LeetCode 补拙笔记 日期:2026.06.07 题目:283. 移动零
笔记·算法·leetcode
吴阿福|一人公司35 分钟前
类变量和实例变量的命名规范有哪些避坑点?
开发语言·python