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;
    }
};
相关推荐
科雷软件测试2 小时前
Python中itertools.product:快速生成笛卡尔积
开发语言·python
OOJO3 小时前
c++---list介绍
c语言·开发语言·数据结构·c++·算法·list
别或许5 小时前
1、高数----函数极限与连续(知识总结)
算法
派大星~课堂5 小时前
【力扣-142. 环形链表2 ✨】Python笔记
python·leetcode·链表
田梓燊5 小时前
code 560
数据结构·算法·哈希算法
笨笨饿5 小时前
29_Z变换在工程中的实际意义
c语言·开发语言·人工智能·单片机·mcu·算法·机器人
kobesdu5 小时前
综合强度信息的激光雷达去拖尾算法解析和源码实现
算法·机器人·ros·slam·激光雷达
艾为电子6 小时前
【技术帖】让接口不再短命:艾为 C-Shielding™ Type-C智能水汽防护技术解析
c语言·开发语言
weixin_413063216 小时前
记录 MeshFlow-Online-Video-Stabilization 在线稳像
算法·meshflow·实时防抖
会编程的土豆6 小时前
【数据结构与算法】动态规划
数据结构·c++·算法·leetcode·代理模式