Skip to content

Commit db4a2cf

Browse files
author
applewjg
committed
Excel Sheet Column Number
Change-Id: Ib63bab271f501a61843472d94861dfceff692598
1 parent 818f534 commit db4a2cf

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ExcelSheetColumnNumber.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Author: King, [email protected]
3+
Date: Jul 11, 2013
4+
Problem: Unique Binary Search Trees II
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+
25+
public class Solution {
26+
public 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.charAt(i) - 'A' + 1;
31+
}
32+
return res;
33+
}
34+
}

0 commit comments

Comments
 (0)