LeetCode题解:Excel Sheet Column Title
2015-08-26 19:40
381 查看
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
题意:给定一个整数,按照给定的对应关系返回列标题
解决思路:用一个大小为26的数组代表每个数对应的字母,按照输入拼接就可以了。
代码:
For example:
1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB
题意:给定一个整数,按照给定的对应关系返回列标题
解决思路:用一个大小为26的数组代表每个数对应的字母,按照输入拼接就可以了。
代码:
public class Solution { public String convertToTitle(int n) { StringBuilder result = new StringBuilder(); while(n>0){ n--; result.insert(0, (char)('A' + n % 26)); n /= 26; } return result.toString(); } }
相关文章推荐
- Cocos2dx学习笔记4:导演(Director)
- Proud Merchants
- SGU 224
- JavaScript控制各种浏览器全屏模式的方法、属性和事件介绍
- Proud Merchants
- Linux mysql安装问题
- LightOJ 1149 - Factors and Multiples【二分图最大匹配】
- Cocos2dx学习笔记3:基础概念介绍
- 人工智能进入股市操盘获利巨大激荡股市
- 当互联网遇上家装,十大家装O2O混战
- c++ 可重载运算符和不可重载运算符
- MySQL Query 的优化—合理设计并利用索引
- android studio 导入源码
- Kth Largest Element in an Array
- css3的选择器
- See You Again
- 线性筛
- [leetcode-205]Isomorphic Strings(java)
- MongoDB学习八--MongoDB的索引操作
- Android常用控件之AutoCompleteTextView、Spinner