题目描述:

A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28

解题思路:

循环读取数字,从左向右读取,每次该位字符减去A加上一即为该为数字代表的数值,然后每次循环前将之前的结果乘以26.表示该表示为26进制。

代码如下:

public class Solution {
public int titleToNumber(String s) {
int i = 0;
int result = 0;
int length;
if(s == null || (length = s.length()) == 0)
return 0;
while(i < length){
result *= 26;
result += s.charAt(i) - 'A' + 1;
i++;
}
return result;
}
}

  

Java [Leetcode 171]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. 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 ...

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

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

  6. LeetCode 171 Excel Sheet Column Number

    Problem: Given a column title as appear in an Excel sheet, return its corresponding column number. F ...

  7. Leetcode 171 Excel Sheet Column Number python

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

  8. 20. leetcode 171. Excel Sheet Column Number

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

  9. LeetCode 171 Excel Sheet Column Number 解题报告

    题目要求 Given a column title as appear in an Excel sheet, return its corresponding column number. For e ...

随机推荐

  1. 堆栈中的EIP EBP ESP

    EIP,EBP,ESP都是系统的寄存器,里面存的都是些地址.  为什么要说这三个指针,是因为我们系统中栈的实现上离不开他们三个.  我们DC上讲过栈的数据结构,主要有以下特点:  后进先处.(这个强调 ...

  2. Unity3d Android程序嵌入Admob广告条

    原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140441353482/ Seems like using a simple A ...

  3. ZOJ1232 Adventure of Super Mario spfa上的dp

    很早之前听说有一种dp是在图上的dp,然后是在跑SPFA的时候进行dp,所以特地找了一题关于在SPFA的时候dp的. 题意:1~a是村庄 a+1~a+b是城堡,存在m条无向边.求由a+b->1的 ...

  4. PKU 1458 Common Subsequence(最长公共子序列,dp,简单)

    题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...

  5. D&F学数据结构系列——插入排序

    插入排序(insertion sort) 插入排序由P-1趟(pass)排序组成.对于P=1趟到P=N-1趟,插入排序保证从位置0到位置P-1上的元素为已排序状态.插入排序利用了这样的事实:位置0到位 ...

  6. React vs Angular 2: 冰与火之歌

    黄玄 · 3 个月前 本文译自 Angular 2 versus React: There Will Be Blood ,其实之前有人翻译过,但是翻得水平有一点不忍直视,我们不希望浪费这篇好文章. 本 ...

  7. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

  8. windows下eclipse远程连接hadoop错误“Exception in thread"main"java.io.IOException: Call to Master.Hadoop/172.20.145.22:9000 failed ”

    在VMware虚拟机下搭建了hadoop集群,ubuntu-12.04,一台master,三台slave.hadoop-0.20.2版本.在 master机器上利用eclipse-3.3连接hadoo ...

  9. lintcode 中等题:partition array 数组划分

    题目 数组划分 给出一个整数数组nums和一个整数k.划分数组(即移动数组nums中的元素),使得: 所有小于k的元素移到左边 所有大于等于k的元素移到右边 返回数组划分的位置,即数组中第一个位置i, ...

  10. 欧拉工程第71题:Ordered fractions

    题目链接:https://projecteuler.net/problem=71 If n<d and HCF(n,d)=1, it is called a reduced proper fra ...