博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode] Excel Sheet Column Number 求Excel表列序号
阅读量:7110 次
发布时间:2019-06-28

本文共 580 字,大约阅读时间需要 1 分钟。

Related to question

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 for adding this problem and creating all test cases.

 

这题实际上相当于一种二十六进制转十进制的问题,并不难,只要一位一位的转换即可。代码如下:

 

class Solution {public:    int titleToNumber(string s) {        int n = s.size();        int res = 0;        int tmp = 1;        for (int i = n; i >= 1; --i) {            res += (s[i - 1] - 'A' + 1) * tmp;             tmp *= 26;        }        return res;    }};

 

转载地址:http://yslhl.baihongyu.com/

你可能感兴趣的文章
windows中使用Findwindow函数与FindWindowEx函数来实现自动控制、触发第三方软件事件的方法...
查看>>
金额大小写转换(3)
查看>>
浏览器的同源策略和跨域问题
查看>>
SQL SERVER 触发器介绍
查看>>
美国国有企业
查看>>
推送的通知和自定义消息区别
查看>>
c# 解析JSON的几种办法
查看>>
autofs自动挂载
查看>>
JavaWeb学习笔记——过滤器
查看>>
互联网创业原则与创业模式attilax大总结
查看>>
linux无线网络配置_转
查看>>
微信小程序想通过场景化缩短路径
查看>>
手把手教你DIY一个春运迁徙图(一)
查看>>
mysql编码问题
查看>>
Web APi之HttpClient注意事项以及建议
查看>>
Webkit内核探究【2】——css简介
查看>>
[Angular] Ngrx/effects, Action trigger another action
查看>>
原生和jQuery的ajax用法
查看>>
【Linux】Linux中 “there are stopped jobs”问题的解决方案
查看>>
[NPM] Use custom config settings in your npm scripts
查看>>