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 -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28
思路:类似于26进制加法
public class Solution { public int titleToNumber(String s) { if (s == null) return 0; char [] temp = s.toCharArray(); int sum = 0; for(int i = temp.length-1; i >= 0; i--) { sum = sum + ((int)(temp[i]-64))*(int)(Math.pow(26,temp.length-1-i)); } return sum; } }