26进制---Excel Sheet Column Number

For example:

A -> 1
B -> 2
C -> 3
...
Z -> 26
AA -> 27
AB -> 28 
public class Solution {
    public int titleToNumber(String s) {
        int length = s.length();
        int num = 0;
        for(int i = 0; i <length; i++){
            num = num * 26 +(s.charAt(i)-'A'+1);

        }

        return num;
    }
}
点赞