Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, return its corresponding column number.
For example:
A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28
solution:
26 进制,逐位*26相加
public int titleToNumber(String s) {if(s == null ||s.isEmpty()) return 0;if(s.length()==1) return s.charAt(0)-'A'+1;int result = s.charAt(0)-'A'+1;for(int i=1;i<s.length();i++){int cur = s.charAt(i)-'A'+1;result = result*26 + cur;}return result;}