File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,7 @@ Princeton Algorithms [Part 1](https://www.coursera.org/learn/algorithms-part1/)
196
196
* Recursive [ C++] ( problems/math/PascalTriangle.cpp )
197
197
* Iterative [ C++] ( problems/math/PascalTriangle.cpp )
198
198
* Happy number [ Wiki] ( https://en.wikipedia.org/wiki/Happy_number ) [ C++] ( problems/math/HappyNumber.cpp )
199
+ * Excel Sheet Column Number [ C++] ( problems/math/SheetColumnNumber.cpp )
199
200
200
201
## Permutation
201
202
* Permutation of objects [ Java] ( problems/queue/Permutation.java )
Original file line number Diff line number Diff line change
1
+ // Leetcode https://leetcode.com/explore/interview/card/top-interview-questions-medium/113/math/817/
2
+
3
+ #include < iostream>
4
+ #include < string>
5
+ #include < vector>
6
+
7
+ const int BASE = 26 ;
8
+
9
+ int titleToNumber (const std::string& columnTitle)
10
+ {
11
+ int number = 0 ;
12
+ for (auto ch : columnTitle) {
13
+ number = number * BASE + (ch - ' A' + 1 );
14
+ }
15
+ return number;
16
+ }
17
+
18
+ void test (const std::string& columnTitle)
19
+ {
20
+ std::cout << " Column title : " << columnTitle << " , number : " << titleToNumber (columnTitle) << " \n " ;
21
+ std::cout << " =====================================\n " ;
22
+ }
23
+
24
+ int main ()
25
+ {
26
+ test (" A" );
27
+ test (" AB" );
28
+ test (" ZY" );
29
+ test (" FXSHRXW" );
30
+
31
+ return 0 ;
32
+ }
You can’t perform that action at this time.
0 commit comments