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的更多相关文章

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

  2. 【leetcode】Excel Sheet Column Number

    Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as appea ...

  3. LeetCode OJ:Excel Sheet Column Number(表格列数)

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...

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

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

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

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

  8. Leetcode 171 Excel Sheet Column Number python

    题目: Given a column title as appear in an Excel sheet, return its corresponding column number. For ex ...

  9. 20. leetcode 171. Excel Sheet Column Number

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

随机推荐

  1. vs2008 添加与修改模板.

    添加 我的模板: 路径:  C:\Users\Administrator\Documents\Visual Studio 2008\Templates\ItemTemplates\Visual C# ...

  2. .NET设计模式(10):装饰模式(Decorator Pattern)(转)

    概述 在软件系统中,有时候我们会使用继承来扩展对象的功能,但是由于继承为类型引入的静态特质,使得这种扩展方式缺乏灵活性:并且随着子类的增多(扩展功能的增多),各种子类的组合(扩展功能的组合)会导致更多 ...

  3. Native App执行JS

    iOS: - (void)webViewDidFinishLoad:(UIWebView *)webView{        //js方法名+参数    NSString* jsCode = [NSS ...

  4. CSS预处理器实践之Sass、Less大比拼[转]

    什么是CSS预处理器? CSS可以让你做很多事情,但它毕竟是给浏览器认的东西,对开发者来说,Css缺乏很多特性,例如变量.常量以及一些编程语法,代码难易组织和维护.这时Css预处理器就应运而生了.Cs ...

  5. HDU 2671 Can't be easier(数学题,点关于直线对称)

    题目 //数学题//直线 y = k * x + b//直线 ax+by+c=0; 点 (x0,y0); 点到直线距离 d = (ax0+by0+c)/sqrt(a^2+b^2) /********* ...

  6. POJ 1469

    #include<iostream> #include<stdio.h> #include <string.h> #include <vector> # ...

  7. POJ 1419

    #include <iostream> #define MAXN 105 #define max _max using namespace std; int j; bool _m[MAXN ...

  8. ios开发之AppDelegate

    创建应用程序之后之后,默认有AppDelegate.h文件与AppDelegate.m文件.   AppDelegate为何物?  AppDelegate为整个应用的一个代理,提供程序启动.退出等类似 ...

  9. 20款最受欢迎的HTML5游戏引擎收集

    在“最火HTML5 JavaScript游戏引擎”系列文章国外篇(一)中,我们盘点了当下备受开发者推崇的非国产HTML5和JavaScript游戏引擎.在各种2D小游戏逆袭的今天,用HTML5和Jav ...

  10. (6)妈的终于找到能用的nehe sdk了

    在网上下载了有十多个,终于找到一个能用的了 下面是下载地址: http://download.csdn.net/detail/jason_bourn/681620#comment 泪奔啊~