[leetcode]Excel Sheet Column Title
2015-05-14 19:42
337 查看
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.
需要注意的地方就是A-Z是1-26
所以判断每一位的时候都需要n自减一下
class Solution {
public:
string convertToTitle(int n) {
if(n<=0) return "";
string res="";
while(n){
n--;
char tmp=n%26+'A';
res=tmp+res;
n=n/26;
}
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.
需要注意的地方就是A-Z是1-26
所以判断每一位的时候都需要n自减一下
class Solution {
public:
string convertToTitle(int n) {
if(n<=0) return "";
string res="";
while(n){
n--;
char tmp=n%26+'A';
res=tmp+res;
n=n/26;
}
return res;
}
};
相关文章推荐
- leetcode Excel Sheet Column Title
- Leetcode 168. Excel Sheet Column Title
- LeetCode:Excel Sheet Column Title
- 168. Excel Sheet Column Title LeetCode
- leetcode——168——Excel Sheet Column Title
- [LeetCode]186 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(Excel的列向表标题)
- Excel Sheet Column Title -- leetcode
- 168.[LeetCode] Excel Sheet Column Title
- LeetCode 168: Excel Sheet Column Title
- LeetCode[Math]----Excel Sheet Column Title----Excel Sheet Column Number
- LeetCode 168. Excel Sheet Column Title
- leetcode_168题——Excel Sheet Column Title(数学问题)
- leetcode-Excel Sheet Column Title
- [leetcode] Excel Sheet Column Title
- leetcode_168_Excel Sheet Column Title