Skip to content

Commit 351e142

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 77bdc05 + 7c1da56 commit 351e142

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed

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

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

35
public class _11 {
46
public static class Solution1 {
@@ -23,21 +25,39 @@ public static class Solution2 {
2325
* Two pointer technique.
2426
* Well explained here: https://leetcode.com/problems/container-with-most-water/discuss/6100/Simple-and-clear-proofexplanation
2527
*/
28+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
29+
30+
static {
31+
branchCoverage.put("flag1", false);
32+
branchCoverage.put("flag2", false);
33+
branchCoverage.put("flag3", false);
34+
}
35+
2636
public int maxArea(int[] height) {
2737
int max = 0;
2838
int left = 0;
2939
int right = height.length - 1;
3040
while (left < right) {
41+
branchCoverage.put("flag1", true);
3142
max = Math.max(Math.min(height[left], height[right]) * (right - left), max);
3243
if (height[left] <= height[right]) {
3344
/**if this height is shorter, then we'll need to move it to the right to find a higher one so that it's possible to find a larger area.*/
45+
branchCoverage.put("flag2", true);
3446
left++;
3547
} else {
48+
branchCoverage.put("flag3", true);
3649
right--;
3750
}
3851
}
52+
printCoverage();
3953
return max;
4054
}
55+
56+
public void printCoverage() {
57+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
58+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
59+
}
60+
}
4161
}
4262

4363
}

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

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

36
public class _29 {
47

58
public static class Solution1 {
9+
10+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
11+
12+
static {
13+
branchCoverage.put("flag1", false);
14+
branchCoverage.put("flag2", false);
15+
branchCoverage.put("flag3", false);
16+
branchCoverage.put("flag4", false);
17+
branchCoverage.put("flag5", false);
18+
branchCoverage.put("flag6", false);
19+
branchCoverage.put("flag7", false);
20+
}
21+
22+
public void printCoverage() {
23+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
24+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
25+
}
26+
}
27+
628
/**
729
* credit: https://leetcode.com/problems/divide-two-integers/solution/ solution 1
830
* <p>
@@ -16,29 +38,37 @@ public static class Solution1 {
1638
* Space: O(1)
1739
*/
1840
public int divide(int dividend, int divisor) {
19-
if (dividend == Integer.MIN_VALUE && divisor == -1) {
41+
if (dividend == Integer.MIN_VALUE && divisor == -1) { //1
42+
branchCoverage.put("flag1", true);
2043
return Integer.MAX_VALUE;
2144
}
2245
int negativeCount = 0;
23-
if (dividend < 0) {
46+
if (dividend < 0) { //2
47+
branchCoverage.put("flag2", true);
2448
negativeCount++;
25-
} else {
49+
} else { //3
50+
branchCoverage.put("flag3", true);
2651
dividend = -dividend;
2752
}
28-
if (divisor < 0) {
53+
if (divisor < 0) { //4
54+
branchCoverage.put("flag4", true);
2955
negativeCount++;
30-
} else {
56+
} else { //5
57+
branchCoverage.put("flag5", true);
3158
divisor = -divisor;
3259
}
3360

3461
int quotient = 0;
35-
while (dividend <= divisor) {
62+
while (dividend <= divisor) { //6
63+
branchCoverage.put("flag6", true);
3664
dividend -= divisor;
3765
quotient++;
3866
}
39-
if (negativeCount == 1) {
67+
if (negativeCount == 1) { //7
68+
branchCoverage.put("flag7", true);
4069
quotient = -quotient;
4170
}
71+
printCoverage();
4272
return quotient;
4373
}
4474
}
Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,46 @@
11
package com.fishercoder.solutions;
2+
import java.util.HashMap;
3+
import java.util.Map;
24

35
public class _3038 {
6+
7+
private static Map<String, Boolean> branchCoverage = new HashMap<>();
48
public static class Solution1 {
9+
10+
static {
11+
branchCoverage.put("flag1", false);
12+
branchCoverage.put("flag2", false);
13+
branchCoverage.put("flag3", false);
14+
branchCoverage.put("flag4", false);
15+
}
16+
17+
public void printCoverage() {
18+
for (Map.Entry<String, Boolean> entry : branchCoverage.entrySet()) {
19+
System.out.println(entry.getKey() + " was " + (entry.getValue() ? "hit" : "not hit"));
20+
}
21+
}
22+
523
public int maxOperations(int[] nums) {
624
int maxOps = 0;
7-
if (nums == null || nums.length < 2) {
25+
if (nums == null || nums.length < 2) { //1
26+
branchCoverage.put("flag1", true); //1 should not be hit
827
return maxOps;
928
}
1029
maxOps++;
1130
int sum = nums[0] + nums[1];
12-
for (int i = 2; i < nums.length - 1; i += 2) {
13-
if (nums[i] + nums[i + 1] == sum) {
31+
for (int i = 2; i < nums.length - 1; i += 2) { //2
32+
branchCoverage.put("flag2", true);
33+
if (nums[i] + nums[i + 1] == sum) { //3
34+
branchCoverage.put("flag3", true); //3 should not be hit
1435
maxOps++;
15-
} else {
36+
} else { //4
37+
branchCoverage.put("flag4", true);
1638
break;
1739
}
1840
}
41+
printCoverage();
1942
return maxOps;
2043
}
2144
}
2245
}
46+

0 commit comments

Comments
 (0)