|
1 | 1 | package com.fishercoder.solutions;
|
| 2 | +import java.util.HashMap; |
| 3 | +import java.util.Map; |
| 4 | + |
2 | 5 |
|
3 | 6 | public class _487 {
|
4 | 7 |
|
@@ -35,25 +38,45 @@ public static class Solution2 {
|
35 | 38 | /**
|
36 | 39 | * This is a more generic solution adapted from https://leetcode.com/problems/max-consecutive-ones-iii/, just set k = 1 here.
|
37 | 40 | */
|
38 |
| - public static int findMaxConsecutiveOnes(int[] nums) { |
| 41 | + |
| 42 | + private static Map<String, Boolean> branchCoverage = new HashMap<>(); |
| 43 | + static { |
| 44 | + branchCoverage.put("flag1", false); |
| 45 | + branchCoverage.put("flag2", false); |
| 46 | + branchCoverage.put("flag3", false); |
| 47 | + branchCoverage.put("flag4", false); |
| 48 | + } |
| 49 | + |
| 50 | + public int findMaxConsecutiveOnes(int[] nums) { |
39 | 51 | int len = nums.length;
|
40 | 52 | int left = 0;
|
41 | 53 | int right = 0;
|
42 | 54 | int ans = 0;
|
43 | 55 | int k = 1;
|
44 | 56 | for (; right < len; right++) {
|
| 57 | + branchCoverage.put("flag1", true); |
45 | 58 | if (nums[right] == 0) {
|
| 59 | + branchCoverage.put("flag2", true); |
46 | 60 | k--;
|
47 | 61 | }
|
48 | 62 | while (k < 0) {
|
| 63 | + branchCoverage.put("flag3", true); |
49 | 64 | if (nums[left] == 0) {
|
| 65 | + branchCoverage.put("flag4", true); |
50 | 66 | k++;
|
51 | 67 | }
|
52 | 68 | left++;
|
53 | 69 | }
|
54 | 70 | ans = Math.max(ans, right - left + 1);
|
55 | 71 | }
|
| 72 | + printCoverage(); |
56 | 73 | return ans;
|
57 | 74 | }
|
| 75 | + |
| 76 | + public void printCoverage() { |
| 77 | + for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) { |
| 78 | + System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit")); |
| 79 | + } |
| 80 | + } |
58 | 81 | }
|
59 | 82 | }
|
0 commit comments