File tree 2 files changed +26
-4
lines changed
main/java/com/thealgorithms/strings
test/java/com/thealgorithms/strings
2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change 6
6
// Every close bracket has a corresponding open bracket of the same type.
7
7
8
8
9
+ import java .util .*;
10
+
9
11
public class ValidParentheses {
12
+ public static HashSet <String > branchesReached = new HashSet <>();
10
13
public static boolean isValid (String s ) {
11
14
char [] stack = new char [s .length ()];
12
15
int head = 0 ;
13
16
for (char c : s .toCharArray ()) {
17
+ branchesReached .add ("1.1" );
14
18
switch (c ) {
15
19
case '{' :
20
+ branchesReached .add ("1.2" );
16
21
case '[' :
22
+ branchesReached .add ("1.3" );
17
23
case '(' :
18
24
stack [head ++] = c ;
19
25
break ;
20
26
case '}' :
21
- if (head == 0 || stack [--head ] != '{' ) return false ;
27
+ branchesReached .add ("1.4.1" );
28
+ if (head == 0 || stack [--head ] != '{' ) {
29
+ branchesReached .add ("1.4.2" );
30
+ return false ;
31
+ }
22
32
break ;
23
33
case ')' :
24
- if (head == 0 || stack [--head ] != '(' ) return false ;
34
+ branchesReached .add ("1.5.1" );
35
+ if (head == 0 || stack [--head ] != '(' ) {
36
+ branchesReached .add ("1.5.2" );
37
+ return false ;
38
+ }
25
39
break ;
26
40
case ']' :
27
- if (head == 0 || stack [--head ] != '[' ) return false ;
41
+ branchesReached .add ("1.6.1" );
42
+ if (head == 0 || stack [--head ] != '[' ) {
43
+ branchesReached .add ("1.6.2" );
44
+ return false ;
45
+ }
28
46
break ;
29
47
}
30
48
}
Original file line number Diff line number Diff line change 1
1
package com .thealgorithms .strings ;
2
2
3
+ import com .thealgorithms .datastructures .hashmap .hashing .HashMap ;
4
+ import org .junit .jupiter .api .AfterAll ;
3
5
import org .junit .jupiter .api .Test ;
4
6
import static org .junit .jupiter .api .Assertions .*;
5
7
@@ -20,5 +22,7 @@ void testTwo() {
20
22
void testThree () {
21
23
assertEquals (false , ValidParentheses .isValid ("(]" ));
22
24
}
23
-
25
+
26
+ @ AfterAll
27
+ static void printCoverage (){System .out .println (ValidParentheses .branchesReached );}
24
28
}
You can’t perform that action at this time.
0 commit comments