Skip to content

Commit 77bdc05

Browse files
committed
Added Flags to file 487 solution 2
1 parent b4ae3cc commit 77bdc05

File tree

1 file changed

+24
-1
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package com.fishercoder.solutions;
2+
import java.util.HashMap;
3+
import java.util.Map;
4+
25

36
public class _487 {
47

@@ -35,25 +38,45 @@ public static class Solution2 {
3538
/**
3639
* This is a more generic solution adapted from https://leetcode.com/problems/max-consecutive-ones-iii/, just set k = 1 here.
3740
*/
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) {
3951
int len = nums.length;
4052
int left = 0;
4153
int right = 0;
4254
int ans = 0;
4355
int k = 1;
4456
for (; right < len; right++) {
57+
branchCoverage.put("flag1", true);
4558
if (nums[right] == 0) {
59+
branchCoverage.put("flag2", true);
4660
k--;
4761
}
4862
while (k < 0) {
63+
branchCoverage.put("flag3", true);
4964
if (nums[left] == 0) {
65+
branchCoverage.put("flag4", true);
5066
k++;
5167
}
5268
left++;
5369
}
5470
ans = Math.max(ans, right - left + 1);
5571
}
72+
printCoverage();
5673
return ans;
5774
}
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+
}
5881
}
5982
}

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