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

Credits:

Special thanks to @ifanchu for adding this problem and creating all test cases.

public class Solution {
public String convertToTitle(int n) {
char a[]=new char[27]; a[0]='A';
for(int i=1;i<=26;i++){
a[i]=(char)(a[0]+i-1);
}
if(n<=26)
return (a[n]+"");
String s="";
while(n>26){
int r = n%26;
if(r==0){
r=26;
n-=26;
}
s = a[r]+s;
n/=26;
}
s = a[n]+s;
return s;
}
}

Excel Sheet Column Title的更多相关文章

  1. 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number

    题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...

  2. 【leetcode】Excel Sheet Column Title

    Excel Sheet Column Title Given a non-zero positive integer, return its corresponding column title as ...

  3. Excel Sheet Column Title & Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  4. 168. Excel Sheet Column Title

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  5. 2016.5.19——Excel Sheet Column Title

    Excel Sheet Column Title 本题收获: 1.由int型转换为整型(string),如何转化, res = 'A'+(n-1)%26和之前由A-z转化为十进制相反,res = s[ ...

  6. Leetcode Excel Sheet Column Number (C++) && Excel Sheet Column Title ( Python)

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  7. Excel Sheet Column Title&&Excel Sheet Column Number

    Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...

  8. LeetCode 168. Excel表列名称(Excel Sheet Column Title)

    168. Excel表列名称 168. Excel Sheet Column Title 题目描述 给定一个正整数,返回它在 Excel 表中相对应的列名称. LeetCode168. Excel S ...

  9. LeetCode_168. Excel Sheet Column Title

    168. Excel Sheet Column Title Easy Given a positive integer, return its corresponding column title a ...

  10. [LeetCode] Excel Sheet Column Title 求Excel表列名称

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

随机推荐

  1. 应用商店后台MIS的一些思考

    1.有些签名验证的工作应该在开发者上传APP的时候进行校验: 1)如果是更新新版本(包名packagename一致),那么需要验证两个APK的包的签名是否一致,不一致的,应该限制上传,除非先下架旧的A ...

  2. 【日记】搭建一个node本地服务器

    用node搭建一个本地http服务器.首先了解htpp服务器原理 HTTP协议定义Web客户端如何从Web服务器请求Web页面,以及服务器如何把Web页面传送给客户端.HTTP协议采用了请求/响应模型 ...

  3. 循环获取DataTable

    DataTable ddtt = tq.Table("); string strName = ""; //DataTable ddtt = dataSet.Tables[ ...

  4. React学习笔记-4-什么是生命周期

    什么是声明周期?组件本质上就是状态机,输入确定,输出一定确定.如何理解这一点?react有两个特点,第一个就是去除了所有的手动dom操作,也就是使用jsx.第二个就是组件把状态和结果一一对应起来,从而 ...

  5. [知识笔记]Java 基本数据类型的大小、取值范围、默认值

    数据类型 大小(字节) 范围 默认值 boolean 1/8(1bit) true/false false byte 1 -128~127 (-2^7~2^7-1) 0 short 2 -32768~ ...

  6. 转:大神提出来的java服务器方面面试问题(当作自己的学习目标平时得多注意)

    因为一些个人原因,陆陆续续参加了一些校招补招.社招的笔试和面试(BAT),也包括一些国外公司(Spotify, Google, Ericsson),最后有幸被网易收入麾下,拿到了S.下面罗列一些我复习 ...

  7. Delphi容器类之---TOrderedList、TStack、TQueue、TObjectStack、TObjectQueue

    TOrderedList.TStack.TQueue Contnrs单元还定义了其他三个类:TOrderedList.TStack.TQueue TOrderedList TOrderedList = ...

  8. 剑指Offer-【面试题07:两个栈实现队列】

    package com.cxz.question7; import java.util.Stack; /** * 用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail 和del ...

  9. SQL Server 系统数据库

    Sql Server的系统数据库分为:master.model.msdb,resouce和tempdb,这五个数据库在SQL Server中各司其职,作为研发人员,很有必要了解这几个数据库的职责,下面 ...

  10. 安装minicom

    安装配置过程: 1.sudo apt-get install minicom 2.执行:sudo minicom -s 配置minicom 切记加sudo 3.然后选择Serial port setu ...