Excel Sheet Column Title&&Excel Sheet Column Number
Excel Sheet Column Title
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 C++版:
class Solution {
public:
string convertToTitle(int n) {
string ret = "";
while(n)
{
ret = (char)((n-)%+'A') + ret;
n = (n-)/;
}
return ret;
}
};
Python版:
1,10进制转成26进制,但需要注意先减1。
2,chr(i):返回整数i对应的ASCII字符。与ord()作用相反。
3,逆序返回可以直接用res[::-1]。
4,python中string类型的数据没有append(var), insert(index,var),pop(var)等list所拥有的方法,需要特别的注意.
5,python不用像c++那样声明数据类型,但也可以声明,如string=''(字符串),list=[](列表),tuple=(1,1,2,3,)(元组声明后不能更改)
class Solution:
# @param {integer} n
# @return {string}
def convertToTitle(self, n):
flag=n
string=''
while n!=:
rem=(n-)%
n=(n-)/
rem=chr(rem+)
string+=(rem)
return string[::-]
Excel Sheet Column Number
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28
26进制转10进制,因为'A'以1开头而不是0,因此要“+1”
class Solution {
public:
int titleToNumber(string s) {
int len=s.size();
int res=;
for(int i=;i<len;i++)
res=res*+s[i]-'A'+;
return res;
}
};
Excel Sheet Column Title&&Excel Sheet Column Number的更多相关文章
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number
题目描述: Excel Sheet Column Title Given a positive integer, return its corresponding column title as ap ...
- 【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 ...
- 【leetcode】Excel Sheet Column Title & Excel Sheet Column Number (easy)
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- Excel Sheet Column Title & Excel Sheet Column Number
Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear i ...
- 168 Excel Sheet Column Title Excel表列名称
给定一个正整数,返回它在Excel表中相对应的列名称.示例: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -&g ...
- 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表列名称
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- [Swift]LeetCode171. Excel表列序号 | Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...
- [LeetCode] 168. Excel Sheet Column Title 求Excel表列名称
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
随机推荐
- ContestHunter暑假欢乐赛 SRM 04
逃了一场SRM(躺 A题可以看成0点到1点,有p的几率从0到1,1-p几率不动,求0到1的期望步数.很显然概率是不降序列数/n!,然后列个方程E[0] = E[0] * (1 - p) + 1,解得E ...
- 洛谷P4198 楼房重建 (分块)
洛谷P4198 楼房重建 题目描述 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题, ...
- ReentrantLock和synchronized区别和联系?
相同:ReentrantLock提供了synchronized类似的功能和内存语义,都是可重入锁. 不同: 1.ReentrantLock功能性方面更全面,比如时间锁等候,可中断锁等候,锁投票等,因此 ...
- 【IntelliJ IDEA 12使用】导入外部包
以前用eclipse,现在用IntelliJ IDEA,发现它确实是个很不错的工具. 用IntelliJ IDEA12这个版本导入外部JAR包,这样来操作,打开Project Structure,在m ...
- How to configue session timeout in Hive
This article explains how to configure the following settings in Hive:hive.server2.session.check.int ...
- sql service (case when then else end ..... group by)
1. 原表: courseid coursename score ------------------------------------- 1 java 70 2 oracle 90 3 xml 4 ...
- vue-transition-animation
<!Doctype> <html> <head> <meta charset="utf-8"> <meta name=&quo ...
- ZooKeeper动态配置(十四)
概述 在3.5.0发行之前,ZK的全体成员和所有其它的配置参数是静态加载的在启动的时候并且在运行的时候不可变.操作员诉诸于"滚动重启" - 一个手动密集和改变配置文件容易出错的方法 ...
- EL表达式获取对象属性的原理
EL表达式获取对象属性的原理是这样的: 以表达式${user.name}为例 EL表达式会根据name去User类里寻找这个name的get方法,此时会自动把name首字母大写并加上get前缀,一旦找 ...
- LightOJ 1226 - One Unit Machine Lucas/组合数取模
题意:按要求完成n个任务,每个任务必须进行a[i]次才算完成,且按要求,第i个任务必须在大于i任务完成之前完成,问有多少种完成顺序的组合.(n<=1000 a[i] <= 1e6 mod ...