Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f932595

Browse files
solves #2455: Average Value of Even Numbers That Are Divisible by Three in java
1 parent 9e81a0e commit f932595

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@
776776
| 2441 | [Largest Positive Integer That Exists With Its Negative](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative) | [![Java](assets/java.png)](src/LargestPositiveIntegerThatExistsWithItsNegative.java) | |
777777
| 2446 | [Determine if Two Events Have Conflict](https://leetcode.com/problems/determine-if-two-events-have-conflict) | [![Java](assets/java.png)](src/DetermineIfTwoEventsHaveConflict.java) | |
778778
| 2451 | [Odd String Difference](https://leetcode.com/problems/odd-string-difference) | [![Java](assets/java.png)](src/OddStringDifference.java) | |
779-
| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | | |
779+
| 2455 | [Average Value of Even Numbers That Are Divisible by Three](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three) | [![Java](assets/java.png)](src/AverageValueOfEvenNumbersThatAreDivisibleByThree.java) | |
780780
| 2460 | [Apply Operations to an Array](https://leetcode.com/problems/apply-operations-to-an-array) | | |
781781
| 2465 | [Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages) | | |
782782
| 2466 | [Count Ways To Build Good Strings](https://leetcode.com/problems/count-ways-to-build-good-strings) | | |
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class AverageValueOfEvenNumbersThatAreDivisibleByThree {
6+
public int averageValue(int[] array) {
7+
int sum = 0, count = 0;
8+
for (int element : array) {
9+
if (element % 6 == 0) {
10+
sum += element;
11+
count++;
12+
}
13+
}
14+
return count == 0 ? 0 : sum / count;
15+
}
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /