File tree Expand file tree Collapse file tree 2 files changed +22
-23
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +22
-23
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
3
/**
4
+ * 551. Student Attendance Record I
5
+ *
4
6
* You are given a string representing an attendance record for a student. The record only contains the following three characters:
5
7
6
8
'A' : Absent.
21
23
*/
22
24
public class _551 {
23
25
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 ) {
38
33
return false ;
39
34
}
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 --;
40
45
}
41
- i --;
42
46
}
47
+ return true ;
43
48
}
44
- return true ;
45
49
}
46
50
47
51
}
Original file line number Diff line number Diff line change 1
1
package com .fishercoder ;
2
2
3
3
import com .fishercoder .solutions ._551 ;
4
- import org .junit .Before ;
5
4
import org .junit .BeforeClass ;
6
5
import org .junit .Test ;
7
6
8
7
import static junit .framework .Assert .assertEquals ;
9
8
10
9
public class _551Test {
11
- private static _551 test ;
10
+ private static _551 . Solution1 test ;
12
11
private static boolean expected ;
13
12
private static boolean actual ;
14
13
private static String s ;
15
14
16
15
@ BeforeClass
17
16
public static void setup () {
18
- test = new _551 ();
19
- }
20
-
21
- @ Before
22
- public void setupForEachTest () {
17
+ test = new _551 .Solution1 ();
23
18
}
24
19
25
20
@ Test
You can’t perform that action at this time.
0 commit comments