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 11package 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.
2123 */
2224public 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}
Original file line number Diff line number Diff line change 11package com .fishercoder ;
22
33import com .fishercoder .solutions ._551 ;
4- import org .junit .Before ;
54import org .junit .BeforeClass ;
65import org .junit .Test ;
76
87import static junit .framework .Assert .assertEquals ;
98
109public 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
You can’t perform that action at this time.
0 commit comments