原题链接在这里:https://leetcode.com/problems/excel-sheet-column-number/
题目:
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
题解:
Time O(n), Space O(1).
AC Java:
1 public class Solution { 2 public int titleToNumber(String s) { 3 if(s == null || s.length() == 0){ 4 throw new IllegalArgumentException("Invalid input string."); 5 } 6 int res = 0; 7 for(int i = 0; i<s.length(); i++){ 8 res = res*26 + (int)(s.charAt(i)-'A') + 1; 9 } 10 return res; 11 } 12 }