首页 > 代码库 > Excel Sheet Column Number

Excel Sheet Column Number

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 

 一样的。

 1 public class Solution { 2     public int titleToNumber(String s) { 3         int result = 0; 4         int level = 1; 5         for(int i = s.length() - 1; i > -1; i --){ 6             result += (s.charAt(i) - ‘A‘ + 1) * level; 7             level *= 26; 8         } 9         return result;10     }11 }

 

Excel Sheet Column Number