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