File tree 2 files changed +23
-20
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder
2 files changed +23
-20
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
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.
4
7
5
8
For example:
6
9
11
14
Z -> 26
12
15
AA -> 27
13
16
AB -> 28
17
+
14
18
*/
15
19
public class _171 {
16
20
21
+ public static class Solution1 {
17
22
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 ;
24
30
}
25
-
31
+ }
26
32
}
Original file line number Diff line number Diff line change 6
6
7
7
import static org .junit .Assert .assertEquals ;
8
8
9
- /**
10
- * Created by fishercoder on 5/13/17.
11
- */
12
9
public class _171Test {
13
- private static _171 test ;
10
+ private static _171 . Solution1 solution1 ;
14
11
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
+ }
19
16
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
+ }
24
21
}
You can’t perform that action at this time.
0 commit comments