8000 Excel Sheet Column Number · leetcoders/LeetCode@127aeba · GitHub
[go: up one dir, main page]

Skip to content

Commit 127aeba

Browse files
author
applewjg
committed
Excel Sheet Column Number
Change-Id: I7e47737168b8fc66403efe5b527c572f062b3862
1 parent 8762c94 commit 127aeba

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ExcelSheetColumnNumber.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Author: King, wangjingui@outlook.com
3+
Date: Dec 28, 2014
4+
Problem: Excel Sheet Column Number
5+
Difficulty: Medium
6+
Source: https://oj.leetcode.com/problems/excel-sheet-column-number/
7+
Notes:
8+
Related to question Excel Sheet Column Title
9+
10+
Given a column title as appear in an Excel sheet, return its corresponding column number.
11+
12+
For example:
13+
14+
A -> 1
15+
B -> 2
16+
C -> 3
17+
...
18+
Z -> 26
19+
AA -> 27
20+
AB -> 28
21+
22+
Solution: 1. ...
23+
*/
24+
class Solution {
25+
public:
26+
int titleToNumber(string s) {
27+
int res = 0;
28+
if (s.length() == 0) return 0;
29+
for (int i = 0; i < s.length(); ++i) {
30+
res = res * 26 + s[i] - 'A' + 1;
31+
}
32+
return res;
33+
}
34+
};

0 commit comments

Comments
 (0)
0