Excel Sheet Column Title

原创 2016年08月30日 21:30:45

题目:

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 

分析:移位相除,并记录

代码:

class Solution {
public:
    string convertToTitle(int n) {
        string ans="";
        int k=0;
        while(n)
        {
           k=n%26;
        if(k==0)
        {
             k=26;
        }
        ans+=('A'+k-1);
         n-=k;
        n/=26;
        }
        int left=0;
        int right=ans.length()-1;
        
        while(left<right)
        {
            char temp=ans[left];
            ans[left]=ans[right];
            ans[right]=temp;
            left++;
            right--;
        }
        return ans;
    }
};







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

相关文章推荐

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这个数,也...

[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
  • 3198
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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