leetcode(168)Excel Sheet Column Title 简单题
2017-05-22 20:33
363 查看
Excel Sheet Column Title
Given a non-zero 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.
Excel序是这样的:A~Z, AA~ZZ, AAA~ZZZ, ……
给你一个数n,输出相应的字符串
一开始还想写个函数模拟下字符串的加1操作
后来发现这题目就是 10进制数转26进制数
class Solution {
public:
string convertToTitle(int n) {
string ret = "";
while(n)
{
ret = (char)((n-1)%26+'A') + ret;
n = (n-1)/26;
}
return ret;
}
};
Given a non-zero 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
Credits:
Special thanks to @ifanchu for
adding this problem and creating all test cases.
Excel序是这样的:A~Z, AA~ZZ, AAA~ZZZ, ……
给你一个数n,输出相应的字符串
一开始还想写个函数模拟下字符串的加1操作
后来发现这题目就是 10进制数转26进制数
class Solution {
public:
string convertToTitle(int n) {
string ret = "";
while(n)
{
ret = (char)((n-1)%26+'A') + ret;
n = (n-1)/26;
}
return ret;
}
};
相关文章推荐
- [LeetCode]168.Excel Sheet Column Title
- LeetCode 168. Excel Sheet Column Title
- [LeetCode]168 Excel Sheet Column Title
- leetcode 168: Excel Sheet Column Title
- 【LeetCode】168. Excel Sheet Column Title
- [leetcode 168] Excel Sheet Column Title
- Java for LeetCode 168 Excel Sheet Column Title
- [leetcode] 168.Excel Sheet Column Title
- leetcode[168] Excel Sheet Column Title
- 【LeetCode-面试算法经典-Java实现】【168-Excel Sheet Column Title(Excell列标题)】
- 【LeetCode】168.Excel Sheet Column Title
- Leetcode 168 Excel Sheet Column Title
- LeetCode 168: Excel Sheet Column Title
- leetcode-168-Excel Sheet Column Title
- [Leetcode 168, Easy] Excel Sheet Column Title
- 【LeetCode】168. Excel Sheet Column Title
- leetcode-168 Excel Sheet Column Title
- Leetcode_168_Excel Sheet Column Title
- LeetCode(168) Excel Sheet Column Title
- 【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number