168. Excel Sheet Column Title 由数字返回excel的标题
[抄题]:
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"
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
不知道怎么分离位数,以为有的取整 有的取余:都是取余来取出每一位,然后取整缩小
[一句话思路]:
char ((n - 1) % 26 + 'A') 注意要减1
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
- 注意下新添加的数字若在左边,则需要写成res = new + res
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
取余来取出每一位,然后取整缩小
[复杂度]:Time complexity: O(1) Space complexity: O(1)
[英文数据结构或算法,为什么不用别的数据结构或算法]:
[关键模板化代码]:
ans = (char) ((n - 1) % 26 + 'A') + ans;
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
[代码风格] :
class Solution {
public String convertToTitle(int n) {
String ans = "";
while (n != 0) {
ans = (char) ((n - 1) % 26 + 'A') + ans;
n = (n - 1) / 26;
}
return ans;
}
}
168. Excel Sheet Column Title 由数字返回excel的标题的更多相关文章
- LeetCode 168. Excel表列名称(Excel Sheet Column Title)
168. Excel表列名称 168. Excel Sheet Column Title 题目描述 给定一个正整数,返回它在 Excel 表中相对应的列名称. LeetCode168. Excel S ...
- 【LeetCode】168 & 171- Excel Sheet Column Title & Excel Sheet Column Number
168 - Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...
- 168. Excel Sheet Column Title
Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...
- 2016.5.19——Excel Sheet Column Title
Excel Sheet Column Title 本题收获: 1.由int型转换为整型(string),如何转化, res = 'A'+(n-1)%26和之前由A-z转化为十进制相反,res = s[ ...
- 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 ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number
题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...
- Excel Sheet Column Title & Excel Sheet Column Number
Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...
- Excel Sheet Column Title&&Excel Sheet Column Number
Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...
- LeetCode_168. Excel Sheet Column Title
168. Excel Sheet Column Title Easy Given a positive integer, return its corresponding column title a ...
随机推荐
- Friendly ARM linux交叉编译问题解决
ARM-LINUX-GCC 安装参考:(笔记)Ubuntu下安装arm-linux-gcc-4.4.3.tar.gz (交叉编译环境) 然而安装完成之后运行 arm-linux-gcc -v (注意g ...
- 【英语】Bingo口语笔记(83) - hell系列
- JVM年轻代(young generation)老年代(old generation tenured)持久代(permanent generation)GC
关于jvm内存代,看到这篇文章,转发下 链接地址 ---多谢 虚拟机中的共划分为三个代:年轻代(Young Generation).老年代(Old Generation)和持久代(Permanent ...
- POJ3764,BZOJ1954 The xor-longest Path
题意 In an edge-weighted tree, the xor-length of a path p is defined as the xor sum of the weights of ...
- ①HttpURLConnection通过报文提交
在进行短信发送的接口,因厂家不同,有的厂家会采用报文的格式进行短信请求的发送与接收.本文主要介绍利用HttpURLConnection进行短信报文的请求与响应. 一般的url请求分为两种,一种是GET ...
- python3之scrapy安装使用
需要安装的包 pip install scrapy selenium 可能需要卸载重装的模块 lxml cryptography cffi pypiwin32 pip uninstall xx ...
- java使用sftp下载远程服务器文件
使用的是springboot的项目,只是贴出主要配置与类,代码较长,可以先折叠: 参考:https://www.cnblogs.com/xyzq/p/7049369.html 操作工具类SftpUti ...
- (转)oracle的split函数
本文转载自:http://www.cnblogs.com/linbaoji/archive/2009/09/17/1568252.html PL/SQL 中没有split函数,需要自己写. 代码: c ...
- 第15届浙江省赛 E LIS
LIS Time Limit: 1 Second Memory Limit: 65536 KB Special Judge DreamGrid is learning the LI ...
- STL的一些技巧函数使用
1.emplace() 函数和 emplace_back() 函数 C++11的STL中新增加了emplace() 函数和 emplace_back() 函数,用来实现insert() 函数和 pus ...