LeetCode Excel Sheet Column Title

网友投稿 508 2022-11-11

LeetCode Excel Sheet Column Title

LeetCode Excel Sheet Column Title

1.题目

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB

2.解决方案1

class Solution {public: string convertToTitle(int n) { string result; string array[26] = {"A", "B", "C", "D", "E", "F" , "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; while(n > 0){ int indexNum = n % 26; if(indexNum == 0){ indexNum = 26; } result = array[indexNum - 1] + result; n = (n-1) / 26; } return result; }};

思路:就是26进制的概念,跟这题类似​​《​​​​Reverse Integer 反转一个int数》​​

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
下一篇:PhotoShop 矢量蒙板
相关文章

 发表评论

暂时没有评论,来抢沙发吧~