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 小时前
vllm教程-00-前言与导读
人工智能·算法·vllm
AI情绪识别开源3 小时前
检信AI高一分班分科智选评估系统 v2.0测试报告
开发语言·数据结构·人工智能·科技
纯.Pure_Jin(g)3 小时前
靶场PHP函数整理+防御方式
开发语言·php·ctf
IT毕设实战小研3 小时前
电影数据可视化推荐系统
大数据·后端·爬虫·python·算法·信息可视化·课程设计
且随疾风前行.3 小时前
从驱动来分析服务的添加过程
算法
zl.rs3 小时前
配置更适合生产环境的coredump
c++
CoderYanger4 小时前
A.每日一题:输入单词需要的最少按键次数 Ⅰ+Ⅱ
java·数据结构·算法·leetcode·面试
海兰4 小时前
【 Python 量化交易】第3章:金融基础概念
开发语言·python·金融
一木 之林4 小时前
三.C++ 内存管理(进阶)(二)
开发语言·arm开发·c++
吴声子夜歌4 小时前
Java——类、对象及方法(一)
java·开发语言