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进制转10进制
[注意事项]
1)s == null的处理
[Code]
1 public class Solution { 2 public int titleToNumber(String s) 3 { 4 int num =0; 5 if (s==null) return num; 6 for (int i =0;i<s.length();i++) 7 { 8 num=num*26+(s.charAt(i)-'A'+1); 9 } 10 11 return num; 12 13 } 14 }
reference: http://www.danielbit.com/blog/puzzle/leetcode/leetcode-excel-sheet-column-number