Excel Sheet Column Number(Easy)

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

Java实现

public int titleToNumber(String s) {
    if(s==null || s.length()<=0)
        return 0;

    char[] title = s.toCharArray();
    int number = 0;
    for(char c: title) {
        number = number * 26 + (c - 'A' + 1);
    }
    return number;
}

results matching ""

    No results matching ""