- Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathExcelColumnNumber.cpp
More file actions
Latest commit
46 lines (26 loc) · 724 Bytes
/
Copy pathExcelColumnNumber.cpp
File metadata and controls
46 lines (26 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
https://www.interviewbit.com/problems/excel-column-number/
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
*/
intSolution::titleToNumber(string A)
{
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
int res=0;
for(auto ch : A)
{
res *= 26;
res += ch-'A'+1;
}
return res; // O(n), O(1)
}