| 18 | class Solution { |
| 19 | public: |
| 20 | int titleToNumber(string s) { |
| 21 | |
| 22 | int power=0, colnum=0; |
| 23 | |
| 24 | while(!s.empty()) { |
| 25 | |
| 26 | colnum += (s[s.size()-1] - 'A' + 1)*pow(26, power); |
| 27 | power++; |
| 28 | s=s.substr(0, s.size()-1); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | return colnum; |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | //Complexity: O(n) |