Skip to content

Commit abb25fd

Browse files
refactor 551
1 parent b5c7fb9 commit abb25fd

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder.solutions;
22

33
/**
4+
* 551. Student Attendance Record I
5+
*
46
* You are given a string representing an attendance record for a student. The record only contains the following three characters:
57
68
'A' : Absent.
@@ -21,27 +23,29 @@
2123
*/
2224
public class _551 {
2325

24-
public boolean checkRecord(String s) {
25-
int aCount = 0;
26-
for (int i = 0; i < s.length(); i++) {
27-
if ( s.charAt(i) == 'A') {
28-
aCount++;
29-
if (aCount > 1) {
30-
return false;
31-
}
32-
} else if (s.charAt(i) == 'L') {
33-
int continuousLCount = 0;
34-
while (i < s.length() && s.charAt(i) == 'L') {
35-
i++;
36-
continuousLCount++;
37-
if (continuousLCount > 2) {
26+
public static class Solution1 {
27+
public boolean checkRecord(String s) {
28+
int aCount = 0;
29+
for (int i = 0; i < s.length(); i++) {
30+
if (s.charAt(i) == 'A') {
31+
aCount++;
32+
if (aCount > 1) {
3833
return false;
3934
}
35+
} else if (s.charAt(i) == 'L') {
36+
int continuousLCount = 0;
37+
while (i < s.length() && s.charAt(i) == 'L') {
38+
i++;
39+
continuousLCount++;
40+
if (continuousLCount > 2) {
41+
return false;
42+
}
43+
}
44+
i--;
4045
}
41-
i--;
4246
}
47+
return true;
4348
}
44-
return true;
4549
}
4650

4751
}

src/test/java/com/fishercoder/_551Test.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
package com.fishercoder;
22

33
import com.fishercoder.solutions._551;
4-
import org.junit.Before;
54
import org.junit.BeforeClass;
65
import org.junit.Test;
76

87
import static junit.framework.Assert.assertEquals;
98

109
public class _551Test {
11-
private static _551 test;
10+
private static _551.Solution1 test;
1211
private static boolean expected;
1312
private static boolean actual;
1413
private static String s;
1514

1615
@BeforeClass
1716
public static void setup() {
18-
test = new _551();
19-
}
20-
21-
@Before
22-
public void setupForEachTest() {
17+
test = new _551.Solution1();
2318
}
2419

2520
@Test

0 commit comments

Comments
 (0)