Created
April 28, 2016 20:57
-
-
Save cruxrebels/0a6efda9a7d59317b72eac2777ecff93 to your computer and use it in GitHub Desktop.
Given a column title as appears in an Excel sheet, return its corresponding column number. Example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 Tags: InterviewBit Math Problems https://www.interviewbit.com/problems/excel-column-number/
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
int Solution::titleToNumber(string A) { | |
auto n = A.length(); | |
int value = 0; | |
for (auto i=0; i<n; ++i) | |
{ | |
value += pow(26, i)*(A[n-(i+1)] - 'A' + 1); | |
} | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment