Excel Sheet Column Title

原创 2015年07月09日 21:41:57

1 题目描述

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 

2 解题思路

将10进制转化为26进制,只不过是用字母表示。通知需要注意,因为不是从0开始,因此需要进行-1操作。参考文章:http://www.cnblogs.com/ganganloveu/p/4175848.htm

3 源代码

package com.larry.easy;

public class ExcelSheetColumnTitle {
	public String convertToTitle(int n) {
		String ret = "";
        while(n > 0)
        {
            ret = (char)((n-1)%26+'A') + ret;
            n = (n-1)/26;
        }
        return ret;
    }
}


相关文章推荐

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
  • 244

[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
  • 3340
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Excel Sheet Column Title
举报原因:
原因补充:

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