Skip to content

Commit 26e700c

Browse files
refactor 171
1 parent cf6a92e commit 26e700c

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.fishercoder.solutions;
22

3-
/**Given a column title as appear in an Excel sheet, return its corresponding column number.
3+
/**
4+
* 170. Two Sum III - Data structure design
5+
*
6+
* Given a column title as appear in an Excel sheet, return its corresponding column number.
47
58
For example:
69
@@ -11,16 +14,19 @@
1114
Z -> 26
1215
AA -> 27
1316
AB -> 28
17+
1418
*/
1519
public class _171 {
1620

21+
public static class Solution1 {
1722
public int titleToNumber(String s) {
18-
char[] c = s.toCharArray();
19-
int result = 0;
20-
for (int i = s.length() - 1; i >= 0; i--) {
21-
result += (c[i] - 64) * ((int) Math.pow(26, s.length() - i - 1));//The ASCII value of A is 65
22-
}
23-
return result;
23+
char[] c = s.toCharArray();
24+
int result = 0;
25+
for (int i = s.length() - 1; i >= 0; i--) {
26+
result +=
27+
(c[i] - 64) * ((int) Math.pow(26, s.length() - i - 1));//The ASCII value of A is 65
28+
}
29+
return result;
2430
}
25-
31+
}
2632
}

src/test/java/com/fishercoder/_171Test.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
import static org.junit.Assert.assertEquals;
88

9-
/**
10-
* Created by fishercoder on 5/13/17.
11-
*/
129
public class _171Test {
13-
private static _171 test;
10+
private static _171.Solution1 solution1;
1411

15-
@BeforeClass
16-
public static void setup() {
17-
test = new _171();
18-
}
12+
@BeforeClass
13+
public static void setup() {
14+
solution1 = new _171.Solution1();
15+
}
1916

20-
@Test
21-
public void test1() {
22-
assertEquals(28, test.titleToNumber("AB"));
23-
}
17+
@Test
18+
public void test1() {
19+
assertEquals(28, solution1.titleToNumber("AB"));
20+
}
2421
}

0 commit comments

Comments
 (0)