leetcode 168 Excel Sheet Column Title
2016-06-18 16:05
453 查看
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution {
public:
string convertToTitle(int n) {
string res = "";
while(n > 0) {
int mod = n%26;
if(mod > 0) {
res += ('A'+mod-1);
n = n/26;
}
else if(mod == 0) {
res += 'Z';
n = n/27;
}
}
reverse(res.begin(), res.end());
return res;
}
};
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
Credits:
Special thanks to @ifanchu for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution {
public:
string convertToTitle(int n) {
string res = "";
while(n > 0) {
int mod = n%26;
if(mod > 0) {
res += ('A'+mod-1);
n = n/26;
}
else if(mod == 0) {
res += 'Z';
n = n/27;
}
}
reverse(res.begin(), res.end());
return res;
}
};
相关文章推荐
- 给分类(Category)添加属性
- iOS tableview cell的展开收缩
- 团队开发项目——个人总结
- 动态规划的题目总结(长期更新)
- 第十四周上机实践项目3:数组类模板
- 12. Integer to Roman
- java 枚举 循环遍历以及一些简单常见的使用
- [bzoj3522] [Poi2014]Hotel
- BZOJ3907 网格
- SystemUI下拉通知栏的源码分析,屏蔽通知栏,监听通知栏下拉动作
- 第一个任务--动手写一个网页
- 三分钟教你学会MVC框架——基于java web开发
- 在Linux上,使用MySQL的yum仓库,安装MySQL
- python 跨语言数据交互、json、pickle(序列化)、urllib、requests(爬虫模块)、XML。
- IOS中div contenteditable=true无法输入
- Divide Two Integers
- javascript 解析json数据获取到item和value
- 通往全栈工程师的捷径 —— React
- HTML5 浅谈Jquery中的bind(),live(),delegate(),on()绑定事件方式
- Mysql安装问题