Skip to content

Commit 8da8f07

Browse files
committed
ava function 24
1 parent 3dc9808 commit 8da8f07

File tree

1 file changed

+20
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+20
-10
lines changed

src/main/java/com/fishercoder/solutions/_24.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder.solutions;
22

33
import com.fishercoder.common.classes.ListNode;
4+
import java.util.HashMap;
5+
import java.util.Map;
46

57
public class _24 {
68
public static class Solution1 {
@@ -24,23 +26,28 @@ public static class Solution2 {
2426
* Iterative approach:
2527
* My completely original on 10/24/2021.
2628
*/
29+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
30+
31+
static {
32+
branchCoverage.put("flag1", false);
33+
branchCoverage.put("flag2", false);
34+
branchCoverage.put("flag3", false);
35+
}
36+
2737
public ListNode swapPairs(ListNode head) {
28-
boolean flag1 = false;
29-
boolean flag2 = false;
30-
boolean flag3 = false;
3138
ListNode pre = new ListNode(-1);
3239
pre.next = head;
3340
ListNode tmp = pre;
3441
while (head != null) {
35-
flag1 = true;
42+
branchCoverage.put("flag1", true);
3643
ListNode third;
3744
ListNode first = head;
3845
ListNode second = head.next;
3946
if (second == null) {
40-
flag2 = true;
47+
branchCoverage.put("flag2", true);
4148
break;
4249
} else {
43-
flag3 = true;
50+
branchCoverage.put("flag3", true);
4451
third = head.next.next;
4552
second.next = first;
4653
first.next = third;
@@ -49,11 +56,14 @@ public ListNode swapPairs(ListNode head) {
4956
}
5057
head = third;
5158
}
52-
System.out.println("Flag1: " + flag1 + "\n");
53-
System.out.println("Flag2: " + flag2 + "\n");
54-
System.out.println("Flag3: " + flag3 + "\n");
59+
printCoverage();
5560
return pre.next;
5661
}
57-
}
5862

63+
public void printCoverage() {
64+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
65+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
66+
}
67+
}
68+
}
5969
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy