Excel Sheet Column Number LeetCode solution in Java

1
class Solution {
2
public int titleToNumber(String columnTitle) {
3
int n = columnTitle.length();
4
int pow = 0;
5
int res = 0;
6
for (int i = n - 1; i >= 0; i--) {
7
char c = columnTitle.charAt(i);
8
res += (c - 64) * Math.pow(26, pow);
9
pow++;
10
}
11

12
return res;
13
}
14
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0