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
This question is very simple, is a 26 of the problem, with the POW (26,i) on the solution, there is a character to the number of the problem, because yesterday did valid Palindrom, the use of ASCII code conversion, so in this side is very handy, is S ' A ' + 1 can turn a into a 1,b and turn it into 2 ~ ~
Just beginning to finish, has been wrong, cout the intermediate results later found that the string reading order error, such as AB Bar, A is read first so is the 0,b is 1; and I think of course A is 1,b is 0; Easy degree of the problem to do is high~ (*^__^*) hehe ...
#include <iostream>using namespacestd;classSolution { Public: intTitletonumber (strings) {intlen=s.length (); if(len==0)return 0; inttemp,temp1=0, num=0; for(inti=len-1; i>=0; i--){ if(s[i]>='A'&&s[i]<='Z') {Temp=s[i]-'A'+1; Temp1= (POW ( -, len-i-1))*temp; } num+=Temp1; } returnnum; }};
Leetcode Excel Sheet Column number