LeetCode:Excel Sheet Column Title

原创 2015年11月20日 16:14:28

问题描述:

Given a 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 

思路:将十进制转变成26进制

代码:

class Solution {
public:
    string convertToTitle(int n) {
         if(n < 1) return "";
        else{
                int cnt = 0;
                string  intToString ="";
                while(n != 0){
                    intToString = char((n - 1) % 26 + 'A') + intToString;
                    n = (n - 1) / 26;
                }
                return intToString;
            }
    }
};


版权声明:本文为博主原创文章,未经博主允许不得转载。

leetcode 之Excel Sheet Column Title

Total Accepted: 9173 Total Submissions: 52899 Given a positive integer, return its corres...

【LeetCode】Excel Sheet Column Title

Excel Sheet Column Title 问题描述见链接。 在这个问题中,其实设计的是类似于二进制、十六进制的一种进位方式,可以认为是二十六进制,然而难点在于A-Z中没有0这个数,也...
  • cczz598
  • cczz598
  • 2015年03月15日 21:21
  • 269

[LeetCode]--168. Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For exam...

[C++]LeetCode: 57 Excel Sheet Column Title

题目: Given a positive integer, return its corresponding column title as appear in an Excel sheet. F...

LeetCode 168. Excel Sheet Column Title 解题报告

题目描述: 168. Excel Sheet Column Title   Given a positive integer, return its corresponding ...

[LeetCode]168.Excel Sheet Column Title

【题目】 Given a positive integer, return its corresponding column title as appear in an Excel sheet. ...

LeetCode: Excel Sheet Column Title

题目:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For e...

<LeetCode OJ> 171 / 168 Excel Sheet Column Number & Title

171. Excel Sheet Column Number My Submissions Question Total Accepted: 58671 Total Submissions: ...

关于LeetCode中Excel Sheet Column Title一题的理解

题目如下: Given a positive integer, return its corresponding column title as appear in an Excel sheet....

LeetCode 168 Excel Sheet Column Title(Excel的列向表标题)

翻译给定一个正整数,返回它作为出现在Excel表中的正确列向标题。例如: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> ...
  • NoMasp
  • NoMasp
  • 2016年01月11日 19:57
  • 3413
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LeetCode:Excel Sheet Column Title
举报原因:
原因补充:

(最多只允许输入30个字)