LeetCode 168. Excel Sheet Column Title
2016-04-14 00:49
357 查看
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 题目:给你一个整数,返回它的如同出现在一个Excel表中对应的的列
class Solution { public: string convertToTitle(int n) { string str; while (n != 0) { str.push_back(((n-1) % 26 + 'A'));//将字母插入字符串 if((n-1)%26==25) //如果n是26的倍数,则减去26 n-=26; n /= 26; } string ret(str.rbegin(),str.rend());//翻转字符串,因为先插入的 //是低位 return ret; } };
相关文章推荐
- Java compiler level does not match the version of the installed Java project
- Python语言进行机器学习的开源项目
- LeetCode 276. Paint Fence(篱笆涂色)
- Linux epoll详解
- You have an error in your SQL syntax;
- Android View 焦点问题(EditText clearFocus)
- Emacs 之列编辑模式
- [RxJS] Creation operators: from, fromArray, fromPromise
- iOS开发总结之项目开发中使用UITableView自定义多级表格&自定义cell
- 数据库自增主键可能产生的问题
- Emacs 之查看帮助
- #每日总结#3
- 二分查找-lintcode
- kFreeBSD有活过来的迹象?UbuntuBSD
- android学习——Handler引起的内存泄露及解决方法
- Volley的使用
- [网络编程]——UDP
- 关于linux启动救援模式进行恢复步骤
- Android SDK Manager无法更新的解决方案
- DES、3DES