Skip to content

Commit 95fcf24

Browse files
authored
2022-10-30 update: added "Average Value of Even Numbers That Are Divisible by Three" (#134)
1 parent 8665875 commit 95fcf24

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
418418
| 2427. Number of Common Factors | [Link](https://leetcode.com/problems/number-of-common-factors/) | [Link](./src/main/java/com/smlnskgmail/jaman/leetcodejava/easy/NumberOfCommonFactors.java) |
419419
| 2432. The Employee That Worked on the Longest Task | [Link](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/) | [Link](./src/main/java/com/smlnskgmail/jaman/leetcodejava/easy/TheEmployeeThatWorkedOnTheLongestTask.java) |
420420
| 2441. Largest Positive Integer That Exists With Its Negative | [Link](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/) | [Link](./src/main/java/com/smlnskgmail/jaman/leetcodejava/easy/LargestPositiveIntegerThatExistsWithItsNegative.java) |
421+
| 2455. Average Value of Even Numbers That Are Divisible by Three | [Link](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/) | [Link](./src/main/java/com/smlnskgmail/jaman/leetcodejava/easy/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) |
421422

422423
### Medium
423424

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.smlnskgmail.jaman.leetcodejava.easy;
2+
3+
// https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/
4+
public class AverageValueOfEvenNumbersThatAreDivisibleByThree {
5+
6+
private final int[] input;
7+
8+
public AverageValueOfEvenNumbersThatAreDivisibleByThree(int[] input) {
9+
this.input = input;
10+
}
11+
12+
public int solution() {
13+
int count = 0;
14+
int sum = 0;
15+
for (int num : input) {
16+
if (num % 6 == 0) {
17+
count++;
18+
sum += num;
19+
}
20+
}
21+
return count != 0 ? sum / count : 0;
22+
}
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.smlnskgmail.jaman.leetcodejava.easy;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class AverageValueOfEvenNumbersThatAreDivisibleByThreeTest {
8+
9+
@Test
10+
public void defaultTest() {
11+
assertEquals(
12+
9,
13+
new AverageValueOfEvenNumbersThatAreDivisibleByThree(
14+
new int[]{1, 3, 6, 10, 12, 15}
15+
).solution()
16+
);
17+
}
18+
19+
}

0 commit comments

Comments
 (0)