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;
    }
};
相关推荐
青春喂了后端13 分钟前
Go Sidecar Status 性能优化
开发语言·性能优化·golang
zh_xuan13 分钟前
PC端操作SQLite数据库
数据库·c++·sqlite
摇滚侠15 分钟前
MyBatis 入门到项目实战 MyBatis 分页插件 65-66
java·开发语言·sql·mybatis
来自于狂人18 分钟前
第5章 记忆管理——让Agent记住事情
人工智能·算法·语言模型·自然语言处理
CHHH_HHH21 分钟前
【C++】哈希表原理与实战:从冲突解决到性能优化
开发语言·数据结构·c++·学习·算法·哈希算法·散列表
Cloud_Shy61821 分钟前
解读《Effective Python 3rd Edition》:从练气到老魔(第七章 Item 48 - 50)
开发语言·人工智能·笔记·python·microsoft·学习方法
快乐的哈士奇25 分钟前
Gmail-邮件自动处理系统
node.js·自动化·excel
sali-tec30 分钟前
C# 基于OpenCv的视觉工作流-章84-包胶有无检测
图像处理·人工智能·opencv·算法·计算机视觉
fpcc35 分钟前
并行编程实战——CUDA编程的pipelines
c++·cuda
Irissgwe36 分钟前
数据结构-排序
数据结构·算法·排序算法