leetcode----------Excel Sheet Column Number

题目

Excel Sheet Column Number

通过率 40.5%
难度 Easy

Related to question Excel Sheet Column Title

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进制,逐个读入字符串的每一个字符进行处理转换,逐个移位;

java代码:
public class Solution {
    public int titleToNumber(String s) {
        int i=0;
        int num=0;
        while(i<s.length()){
            if(s.charAt(i)!='Z'){
                num=num*26+s.charAt(i)-65+1;
            }
            else num=num*26+26;
            i++;
        }
        return num;
    }
}

 

posted @ 2015-01-11 16:16  pku_min  阅读(119)  评论(0编辑  收藏  举报