Skip to content

Commit cde96db

Browse files
committed
feat(leetcode): add No.171
1 parent 6cffa5b commit cde96db

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

171.Excel-Sheet-Column-Number.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// https://leetcode.com/problems/excel-sheet-column-number/
2+
//
3+
// algorithms
4+
// Easy (52.25%)
5+
// Total Accepted: 237,025
6+
// Total Submissions: 453,594
7+
// beats 100.0% of java submissions
8+
9+
10+
class Solution {
11+
public int titleToNumber(String s) {
12+
char[] chs = s.toCharArray();
13+
int length = chs.length;
14+
15+
int base = 1, res = 0;
16+
for (int i = length - 1; i >= 0; i--) {
17+
int bit = (chs[i] - 'A') + 1;
18+
res += bit * base;
19+
base *= 26;
20+
}
21+
22+
return res;
23+
}
24+
}

0 commit comments

Comments
 (0)