Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26e700c

Browse files
refactor 171
1 parentcf6a92e commit26e700c

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
packagecom.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
publicclass_171 {
1620

21+
publicstaticclassSolution1 {
1722
publicinttitleToNumber(Strings) {
18-
char[]c =s.toCharArray();
19-
intresult =0;
20-
for (inti =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-
returnresult;
23+
char[]c =s.toCharArray();
24+
intresult =0;
25+
for (inti =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+
returnresult;
2430
}
25-
31+
}
2632
}

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
importstaticorg.junit.Assert.assertEquals;
88

9-
/**
10-
* Created by fishercoder on 5/13/17.
11-
*/
129
publicclass_171Test {
13-
privatestatic_171test;
10+
privatestatic_171.Solution1solution1;
1411

15-
@BeforeClass
16-
publicstaticvoidsetup() {
17-
test=new_171();
18-
}
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1=new_171.Solution1();
15+
}
1916

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp