leetcode:Excel Sheet Column Number
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进制数字
class Solution {
public:
int titleToNumber(string s) {
int n=0;
for(int i=0;i<s.size();i++)
{
n=n*26+(s[i]-'A'+1);
return n;
}
}
};
编译的时候开始总是出现Line 4: stray ‘\357’ in program错误,后来才知道不小心在程序中打入了全角字符。
其他解法:
A C++ solution Runtime: 0ms
class Solution {
public:
int titleToNumber(string s) {
int res = 0;
for(int i=0; i<s.length(); i++){
int exp = s[i] - 'A' + 1;
res = exp * pow(26, s.length() - i -1) + res;
}
return res;
}
};
leetcode:Excel Sheet Column Number的更多相关文章
- [LeetCode] 171. Excel Sheet Column Number 求Excel表列序号
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- 【leetcode】Excel Sheet Column Number
Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as appea ...
- LeetCode OJ:Excel Sheet Column Number(表格列数)
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- LeetCode 171. Excel Sheet Column Number (Excel 表格列数字)
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- Java for LeetCode 171 Excel Sheet Column Number
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- LeetCode: 171 Excel Sheet Column Number(easy)
题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...
- ✡ leetcode 171. Excel Sheet Column Number 字母转换为数字 --------- java
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
- Leetcode 171 Excel Sheet Column Number python
题目: Given a column title as appear in an Excel sheet, return its corresponding column number. For ex ...
- 20. leetcode 171. Excel Sheet Column Number
Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...
随机推荐
- NYOJ-206 矩形的个数 AC 分类: NYOJ 2013-12-29 22:19 265人阅读 评论(0) 收藏
这题目是小学奥数题目,方法可以百度到,但是,有个难点就是,数据类型大小不够,如果是1000x1000的矩阵,那么就会超过int的范围,所以,就引进了long long的数据类型 #include< ...
- SQL Server 2008 R2评估期已过的解决办法
SQL Server 2008 R2评估期已过的解决办法 发现问题 北美产品测试服每日随机任务没有刷新 每日随机任务是使用数据库作业定期执行操作,重置玩家随机任务项 排查问题 www.2cto. ...
- HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript
HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript Though it's not ...
- Hadoop的RPC框架介绍
为什么会引入RPC: RPC采用客户机/服务器模式.请求程序就是一个客户机,而服务提供程序就是一个服务器.当我们讨论HDFS的,通信可能发生在: Client-NameNode之间,其中NameNod ...
- jQuery .tmpl() 用法
动态请求数据来更新页面是现在非常常用的方法,比如博客评论的分页动态加载,微博的滚动加载和定时请求加载等. 这些情况下,动态请求返回的数据一般不是已拼好的 HTML 就是 JSON 或 XML,总之不在 ...
- swift循环
..< { println(... { println( ":"lala"] for (key,value)in dic { println ...
- Struts2 Convention插件的使用(1)
刚刚查阅官方文档(convention-plugin.html)并学习了Struts2的Convention插件,文章这里只作为一个笔记,建议大家去看官方文档比较清晰和全面. 需要在项目添加这些包 c ...
- 8天学通MongoDB——第三天 细说高级操作
原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/21/2361205.html 今天跟大家分享一下mongodb中比较好玩的知识,主 ...
- Spark源码分析(三)-TaskScheduler创建
原创文章,转载请注明: 转载自http://www.cnblogs.com/tovin/p/3879151.html 在SparkContext创建过程中会调用createTaskScheduler函 ...
- Windows 下 玩转Node.JS
vs一直是用的比较舒服的IDE,一直期望可以支持Node.JS.终于找到了一个工具 NTVS(Node.JS Tool For VS). 主页:https://nodejstools.codeplex ...