Leetcode171. Excel Sheet Column Number
2016-03-03 16:47
253 查看
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
C++代码
class Solution {
public:
int titleToNumber(string s) {
int n = s.size();
int i = n-1;
int sum = 0;
while (i>=0)
{
sum += (s[i] - 64)*pow((double)26, n-1-i);
i--;
}
return sum;
}
};
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
Credits:
Special thanks to @ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
C++代码
class Solution {
public:
int titleToNumber(string s) {
int n = s.size();
int i = n-1;
int sum = 0;
while (i>=0)
{
sum += (s[i] - 64)*pow((double)26, n-1-i);
i--;
}
return sum;
}
};
相关文章推荐
- 经典排序算法
- 老李秘技:loadrunner11是否还支持dblib协议?
- POJ 2940 Wine Trading in Gergovia【贪心】
- 手机版制作H5页面免费工具大集合
- Java 完美判断中文字符
- 【转】Google推荐的图片加载库Glide介绍
- Qt发布打包工具 windeployqt
- Eclipse使用Maven创建Web时错误:Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webap
- java中static{}语句块详解
- 新建cocos2d-xproject
- 输入三个整数,输出最大数和最小数
- poi Excel写数据
- 内存泄漏解决方案
- BZOJ2738: 矩阵乘法
- 兰州大学2016年初试成绩基本要求
- LinearLayout 组件居中显示
- PHP file_get_contents 设置超时时间
- 老李秘技:loadrunner回放脚本错误提示Error: "HTTP Status-Code 500"
- Android日常知识收集之通过一个按钮来控制密码是明文还是暗文显示
- 老李说事:性能测试服务日记