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;
    }
};
相关推荐
浮沉9873 分钟前
二分查找算法例题(一)
算法
C+-C资深大佬4 分钟前
Java 变量:从入门到精通
java·开发语言·python
辞旧 lekkk5 分钟前
【Qt系统相关】鼠标事件
linux·开发语言·qt·学习·计算机外设·萌新
退休倒计时15 分钟前
【每日一题】LeetCode 17. 电话号码的字母组合 TypeScript
算法·leetcode·typescript
chouchuang25 分钟前
day-027-面向对象-下
开发语言·python
粘稠的浆糊26 分钟前
[AtCoder - abc465_d ]X to Y题解
数据结构·c++·算法
誰能久伴不乏27 分钟前
C++11 随机数生成——告别 rand()
开发语言·c++
海清河晏11130 分钟前
数据结构 | 二叉平衡搜索树
开发语言·数据结构·visual studio
鱼儿也有烦恼34 分钟前
数据结构合集
算法·algorithm
kuonyuma41 分钟前
java之动态代理
java·开发语言