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 分钟前
游戏开发,桌面%小游戏,贪吃蛇%demo,基于vs2022,c语言,easyX,无数据库
c语言·开发语言
leoufung19 分钟前
LeetCode 61. 旋转链表(Rotate List)题解与思路详解
leetcode·链表·list
万物挽挽33 分钟前
数据结构核心
数据结构
x***J3481 小时前
Python多线程爬虫
开发语言·爬虫·python
AA陈超1 小时前
从0开始学习 **Lyra Starter Game** 项目
c++·笔记·学习·游戏·ue5·lyra
m***D2861 小时前
Python网络爬虫实战案例
开发语言·爬虫·python
甄心爱学习1 小时前
数据挖掘-聚类方法
人工智能·算法·机器学习
q***T5831 小时前
C++在游戏中的Unreal Engine
c++·游戏·虚幻
保持低旋律节奏1 小时前
C++——C++11特性
开发语言·c++·windows
ID_180079054731 小时前
基于 Python 的淘宝商品详情数据结构化解析:SKU、价格与库存字段提取
开发语言·数据结构·python