Topic:
Related to question Excel Sheet Column Title
Given a column title as appear in an Excel sheet, and return its corresponding column number.
For example:
1, B, 2 C-3 ... 27 AA, Z
idea: This problem and Excel Sheet Column title and is corresponding. This question asks us to convert the letters in Excel into numbers. Observe the law, we just need to figure out the corresponding number of each letter, iterative increase can be, note that the Excel table alphanumeric correspondence is 26 binary.
Attention:
1.26 English letters to correspond to numbers. S[i]-' A ' + 1
Ans = (s[i]-' A ' + 1) + ans * 26;
Complexity: O (N)
AC Code:
Class Solution {public: int Titletonumber (string s) { int ans = 0; if (s.size () = = 0) return ans; for (int i = 0; i < s.size (); i++) { ans = (s[i]-' A ' + 1) + ans *; } return ans; };
[C + +] leetcode:116 Excel Sheet column number (Excel columns coordinates go to numbers)