Saturday, January 3, 2015

171. Excel Sheet Column Number

Q:
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 
A:

public class Solution {
    public int titleToNumber(String s) {
        if(s.length()==0)
            return 0;
        return (1+ s.charAt(s.length()-1)-'A') + titleToNumber(s.substring(0,s.length()-1))*26;
    }
}


Mistakes:







No comments:

Post a Comment