[Algorithm] 171. 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
...Example 1:
Input: "A"
Output: 1Example 2:
Input: "AB"
Output: 28Example 3:
Input: "ZY"
Output: 701
Basiclly, it is 26-based, the same as 10-based,
102 = 1 + 1
previous result * 10 + 0 + 1*10+0=10
previous result * 10 +2 + 10*10+2=102
AAA =
1 +
1 * 26 +1
27 * 26 + 1 = 703
/**
* @param {string} s
* @return {number}
*/
var titleToNumber = function(s) { if (!s) {
return 0;
} let sum = 0;
let len = s.length;
for (let i = 0; i < len; i++) {
sum = sum * 26 + (s[i].charCodeAt() - 64);
} return sum;
};
[Algorithm] 171. Excel Sheet Column Number的更多相关文章
- 171. Excel Sheet Column Number(C++)
171. Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as ...
- LeetCode Javascript实现 100. Same Tree 171. Excel Sheet Column Number
100. Same Tree /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; ...
- leetcode 168. Excel Sheet Column Title 171 Excel Sheet Column Number
题目 //像10进制一样进行 转换 只是要从0开始记录 class Solution { public: string convertToTitle(int n) { char a; string ...
- ✡ 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 ...
- 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
题目: Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, r ...
- 171. Excel Sheet Column Number (Math)
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 (Excel 表格列数字)
Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, retur ...
随机推荐
- SpringBoot扩展点之二:ApplicationRunner和CommandLineRunner的扩展
CommandLineRunner并不是Spring框架原有的概念,它属于SpringBoot应用特定的回调扩展接口: public interface CommandLineRunner { /** ...
- ubuntu中编写shell脚本开机自动启动
编写脚本是为了不用手动去开启各种服务(也是为了偷懒哈哈) 1.进入终端输入 创建一个后缀为.sh的脚本文件 touch test.sh 编辑脚本 vim test.sh test.sh编写脚本内容 ...
- c# DataRow[]转Datatable
方法一: Datatable dt=new Datatable(); //添加列和数据(代码省略) DataRow[] drs = dt.Select("DeviceID='123'&quo ...
- [個人紀錄] windows form , usercontrol design 模式不見
windows form 跟 usercontrol 都變成cs檔 無法點擊進入設計模式 <Compile Include="Form1.cs"/> <Compi ...
- C#读写设置修改调整UVC摄像头画面-曝光
有时,我们需要在C#代码中对摄像头的曝光进行读和写,并立即生效.如何实现呢? 建立基于SharpCamera的项目 首先,请根据之前的一篇博文 点击这里 中的说明,建立基于SharpCamera的摄像 ...
- rest-spring-boot-starter
rest-spring-boot-starter 基于spring boot,统一业务异常处理,统一返回格式包装 依赖 <dependency> <groupId>tk.fis ...
- 锤子剪刀布pat-1018
题目描述 大家应该都会玩“锤子剪刀布”的游戏:现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算最大. 输入描述: 输入第1行给出正整数N(<=105),即双方交 ...
- 关于OA流程相关数据表的设计
一.前言 近期有些同学问起流程的表设计,终于有时间能写下博客,并整理下之前所发布的文章. 之前的文章讲到的表设计,没有给全且还存在漏洞,在这里向各位同学表示歉意.这是我个人最新领悟的一些流程思维,欢迎 ...
- Mybatis架构与原理
一.简介 MyBatis 是一款优秀的持久层框架.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集 Mybatis可以将Sql语句配置在XML文件中,避免将Sql语句硬编码 ...
- vue element-ui tree 根节点固定子节点懒加载 首次加载根节点并展开
关键代码: <el-tree ref="foldTree" node-key="id" :highlight-current="true&quo ...