@@ -74,6 +74,13 @@ public int lengthOfLongestSubstring(String s) {
74
74
}
75
75
}
76
76
77
+ private static Map <String , Boolean > branchCoverage = new HashMap <>();
78
+
79
+ static {
80
+ branchCoverage .put ("flag1" , false );
81
+ branchCoverage .put ("flag2" , false );
82
+ }
83
+
77
84
public static class Solution4 {
78
85
/**
79
86
* Sliding Window Optimized
@@ -82,20 +89,31 @@ public static class Solution4 {
82
89
*/
83
90
public int lengthOfLongestSubstring (String s ) {
84
91
if (s .length () == 0 ) {
92
+ branchCoverage .put ("flag1" , true );
85
93
return 0 ;
86
94
}
87
95
int max = 0 ;
88
96
int [] index = new int [128 ];
89
- /**Try to extend the range (i, j)*/
90
97
for (int i = 0 , j = 0 ; j < s .length (); j ++) {
98
+ branchCoverage .put ("flag2" , true );
91
99
i = Math .max (index [s .charAt (j )], i );
92
100
max = Math .max (max , j - i + 1 );
93
101
index [s .charAt (j )] = j + 1 ;
94
102
}
103
+ printCoverage ();
95
104
return max ;
96
105
}
106
+
107
+ public static void printCoverage () {
108
+ for (Map .Entry <String , Boolean > entry : branchCoverage .entrySet ()) {
109
+ System .out .println (entry .getKey () + " was " + (entry .getValue () ? "hit" : "not hit" ));
110
+ }
111
+ }
112
+
97
113
}
98
114
115
+
116
+
99
117
public static class Solution5 {
100
118
/**
101
119
* Sliding Window, my completely original idea on 9/17/2021.
0 commit comments