File tree 1 file changed +17
-2
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
+ import java .util .HashMap ;
3
+ import java .util .Map ;
2
4
3
5
public class _58 {
4
-
5
6
public static class Solution1 {
7
+ private static Map <String , Boolean > branchCoverage = new HashMap <>();
8
+
9
+ static {
10
+ branchCoverage .put ("flag1" , false );
11
+ branchCoverage .put ("flag2" , false );
12
+ }
13
+
6
14
public int lengthOfLastWord (String s ) {
7
15
if (s == null || s .length () == 0 ) {
16
+ branchCoverage .put ("flag1" , true );
8
17
return 0 ;
9
18
}
10
19
s = s .trim ();
11
20
int n = s .length () - 1 ;
12
21
while (n >= 0 && s .charAt (n ) != ' ' ) {
22
+ branchCoverage .put ("flag2" , true );
13
23
n --;
14
24
}
25
+ printCoverage ();
15
26
return s .length () - n - 1 ;
16
27
}
28
+ public void printCoverage () {
29
+ for (Map .Entry <String , Boolean > entry : branchCoverage .entrySet ()) {
30
+ System .out .println (entry .getKey () + " was " + (entry .getValue () ? "hit" : "not hit" ));
31
+ }
32
+ }
17
33
}
18
-
19
34
}
You can’t perform that action at this time.
0 commit comments