168. Excel Sheet Column Title

Easy

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
...

Example 1:

Input: 1
Output: "A"

Example 2:

Input: 28
Output: "AB"

Example 3:

Input: 701
Output: "ZY"
package leetcode.easy;

public class ExcelSheetColumnTitle {
@org.junit.Test
public void test() {
System.out.println(convertToTitle(1));
System.out.println(convertToTitle(28));
System.out.println(convertToTitle(701));
} public String convertToTitle(int n) {
StringBuffer buffer = new StringBuffer();
while (n > 0) {
n--;
buffer.append((char) ('A' + n % 26));
n /= 26;
}
return buffer.reverse().toString();
}
}

LeetCode_168. 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] Excel Sheet Column Title 求Excel表列名称

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

随机推荐

  1. 解决在macOS下安装了python却没有pip命令的问题【经验总结】

    可以使用brew直接安装python,但是安装完成了之后没有pip命令. pip是常用的python包管理工具,类似于java的maven.第一反应brew install pip,却提示没这货. 可 ...

  2. vb开发最全教程

    https://www.xin3721.com/eschool/VisualBasicenet/

  3. 作业调度系统PBS(Torque)的设置

    1.修改/var/spool/torque/server_priv/目录下的nodes文件 Node1 np=16 gpus=4 Node2 np=16 gpus=4 ... 其中Node1为计算节点 ...

  4. idea项目打包和在linux的部署

    1.将项目打包 2.先clean,后package 3.将打好的包上传到linux 使用cd指令到要上传的文件的目录 4.输入rz -y 5.解压tar.gz格式: tar -zxvf filenam ...

  5. js图片上传 的方法

    先规划出框架 <div id="AQA" style="width:300px; height:200px; background-color:aquamarine ...

  6. 区间连续长度的线段树——洛谷P2894 [USACO08FEB]酒店Hotel

    https://www.luogu.org/problem/P2894 #include<cstdio> #include<iostream> using namespace ...

  7. 微信小程序向本地保存

    提示框: wx.showToast(OBJECT) 显示消息提示框 wx.saveImageToPhotosAlbum({ filePath : "./test.png", //这 ...

  8. 数据结构实验之图论三:判断可达性(SDUT 2138)(简单DFS)

    #include <bits/stdc++.h> using namespace std; int gra[1002][1005]; int vis[1002]; int n,m; voi ...

  9. ckeditor自定义工具栏

    /** * 获取编辑器工具栏自定义参数 * @param type 类型 simple=极简版 basic=基本版 full=完整版 */ function get_ckeditor_toolbar( ...

  10. vue日常学习

    1.$refs可以用来进行父子级间通信.ref被用于作为子组件的索引ID,用以方便的在js中直接访问子组件.用法如下parent.$refs.idname 使用方法: 在父级元素上加上ref属性 &l ...