We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1d04137 commit 9ba3e43Copy full SHA for 9ba3e43
src/_171/171.excel-sheet-column-number.java
@@ -0,0 +1,21 @@
1
+package _171;
2
+
3
+class Solution {
4
+ public int titleToNumber(String s) {
5
+ // the ASCII code of A is 65
6
7
+ int sum = 0;
8
+ for (int i = 0; i < s.length(); i++) {
9
+ sum += Math.pow(26, s.length() - 1 - i) * (s.charAt(i) - 64);
10
+ }
11
12
+ return sum;
13
14
15
+ public static void main(String[] args) {
16
+ System.out.println(new Solution().titleToNumber("A"));
17
+ System.out.println(new Solution().titleToNumber("AB"));
18
+ System.out.println(new Solution().titleToNumber("ZY"));
19
+ System.out.println(new Solution().titleToNumber("AZ"));
20
21
+}
0 commit comments