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

Commitc44bf48

Browse files
refactor 151
1 parente01aced commitc44bf48

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

‎src/main/java/com/fishercoder/solutions/_151.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public String reverseWords(String s) {
2727
returnstringBuilder.substring(0,stringBuilder.length() -1).toString();
2828
}
2929
}
30+
3031
publicstaticclassSolution2 {
3132
publicStringreverseWords(Strings) {
3233
intlen =s.length();
@@ -50,11 +51,10 @@ public String reverseWords(String s) {
5051
}
5152
// word found
5253
Stringword =s.substring(i,j);
53-
if(result.length() ==0) {
54+
if(result.length() ==0) {
5455
result =word;
55-
}
56-
else {
57-
result =word +" "+result;
56+
}else {
57+
result =word +" " +result;
5858
}
5959
i =j +1;
6060
}

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

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,43 @@
77
importstaticorg.junit.Assert.assertEquals;
88

99
publicclass_151Test {
10-
privatestatic_151.Solution1solution1;
11-
privatestatic_151.Solution2solution2;
12-
privatestaticStrings;
13-
14-
@BeforeClass
15-
publicstaticvoidsetup()
16-
{
17-
solution1 =new_151.Solution1();
18-
solution2 =new_151.Solution2();
19-
}
20-
21-
@Test
22-
publicvoidtest1() {
23-
s =" ";
24-
assertEquals("",solution1.reverseWords(s));
25-
}
26-
27-
@Test
28-
publicvoidtest2() {
29-
s =" 1";
30-
assertEquals("1",solution1.reverseWords(s));
31-
}
32-
33-
@Test
34-
publicvoidtest3() {
35-
s =" a b ";
36-
assertEquals("b a",solution1.reverseWords(s));
37-
}
38-
39-
@Test
40-
publicvoidtest4() {
41-
s ="a b c";
42-
assertEquals("c b a",solution1.reverseWords(s));
43-
}
44-
45-
@Test
46-
publicvoidtest5() {
47-
s =" hello world ";
48-
assertEquals("world hello",solution2.reverseWords(s));
49-
}
10+
privatestatic_151.Solution1solution1;
11+
privatestatic_151.Solution2solution2;
12+
privatestaticStrings;
13+
14+
@BeforeClass
15+
publicstaticvoidsetup() {
16+
solution1 =new_151.Solution1();
17+
solution2 =new_151.Solution2();
18+
}
19+
20+
@Test
21+
publicvoidtest1() {
22+
s =" ";
23+
assertEquals("",solution1.reverseWords(s));
24+
}
25+
26+
@Test
27+
publicvoidtest2() {
28+
s =" 1";
29+
assertEquals("1",solution1.reverseWords(s));
30+
}
31+
32+
@Test
33+
publicvoidtest3() {
34+
s =" a b ";
35+
assertEquals("b a",solution1.reverseWords(s));
36+
}
37+
38+
@Test
39+
publicvoidtest4() {
40+
s ="a b c";
41+
assertEquals("c b a",solution1.reverseWords(s));
42+
}
43+
44+
@Test
45+
publicvoidtest5() {
46+
s =" hello world ";
47+
assertEquals("world hello",solution2.reverseWords(s));
48+
}
5049
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp