首页 > 代码库 > Excel Sheet Column Number

Excel Sheet Column Number

For example:

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


看成26进制和10进制之间的转换,Excel Sheet Column Title这道题的逆过程
 1 public class Solution { 2     public int titleToNumber(String s) { 3         int result = 0; 4         for(int i = 0; i < s.length(); i++){ 5             char ch_temp = s.charAt(i); 6             int int_temp = ch_temp - ‘A‘ + 1; 7             result *= 26; 8             result += int_temp; 9         }10         return result;11     }12 }

 

Excel Sheet Column Number