#2455

Average Value of Even Numbers That Are Divisible by Three

pupil · 360 · lc easy +23 · verified · 62.9% accepted · 375 likes · top 65%

Description

Given an integer array nums, compute and return the average (rounded down to the nearest integer) of all elements that are both even and divisible by three.

It is guaranteed at least one such element exists.

Example 1:

Input: nums = [1,3,6,10,12,15]
Output: 9
Explanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.

Example 2:

Input: nums = [1,2,4,7,10]
Output: 0
Explanation: There is no single number that satisfies the requirement, so return 0.

Code

1
2
3