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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int titleToNumber(string s) { | |
int base=0; | |
int res=0; | |
for(int i=s.length()-1; i>=0; i--){ | |
int t=s[i]-'A'+1; | |
res = res+t*pow(26, base++); | |
} | |
return res; | |
} | |
}; |
No comments:
Post a Comment